From 2fff7de0c9854d676e40d367c325b62934bdeef6 Mon Sep 17 00:00:00 2001 From: Jeremie Desautels Date: Fri, 18 Nov 2016 10:55:28 -0600 Subject: [PATCH 01/24] Move source file in new Source folder --- .../CakeMail.RestClient.IntegrationTests}/App.config | 0 .../CakeMail.RestClient.IntegrationTests.csproj | 0 .../CakeMail.RestClient.IntegrationTests}/Campaigns.cs | 0 .../CakeMail.RestClient.IntegrationTests}/Clients.cs | 0 .../CakeMail.RestClient.IntegrationTests}/Countries.cs | 0 .../CakeMail.RestClient.IntegrationTests}/Lists.cs | 0 .../CakeMail.RestClient.IntegrationTests}/Mailings.cs | 0 .../CakeMail.RestClient.IntegrationTests}/Permissions.cs | 0 .../CakeMail.RestClient.IntegrationTests}/Program.cs | 0 .../Properties/AssemblyInfo.cs | 0 .../CakeMail.RestClient.IntegrationTests}/Relays.cs | 0 .../CakeMail.RestClient.IntegrationTests}/SuppressionLists.cs | 0 .../CakeMail.RestClient.IntegrationTests}/Templates.cs | 0 .../CakeMail.RestClient.IntegrationTests}/Timezones.cs | 0 .../CakeMail.RestClient.IntegrationTests}/Triggers.cs | 0 .../CakeMail.RestClient.IntegrationTests}/Users.cs | 0 .../CakeMail.RestClient.IntegrationTests}/packages.config | 0 .../CakeMail.RestClient.UnitTests.csproj | 0 .../CakeMail.RestClient.UnitTests}/CakeMailRestClientTests.cs | 0 .../CakeMail.RestClient.UnitTests}/Campaigns.cs | 0 .../CakeMail.RestClient.UnitTests}/Clients.cs | 0 .../CakeMail.RestClient.UnitTests}/Countries.cs | 0 .../Exceptions/CakeMailException.cs | 0 .../Exceptions/CakeMailPostException.cs | 0 .../CakeMail.RestClient.UnitTests}/Exceptions/HttpException.cs | 0 .../CakeMail.RestClient.UnitTests}/Lists.cs | 0 .../CakeMail.RestClient.UnitTests}/Mailings.cs | 0 .../CakeMail.RestClient.UnitTests}/MockRestClient.cs | 0 .../CakeMail.RestClient.UnitTests}/Permissions.cs | 0 .../CakeMail.RestClient.UnitTests}/Properties/AssemblyInfo.cs | 0 .../CakeMail.RestClient.UnitTests}/Relays.cs | 0 .../CakeMail.RestClient.UnitTests}/Segments.cs | 0 .../CakeMail.RestClient.UnitTests}/SuppressionLists.cs | 0 .../CakeMail.RestClient.UnitTests}/Templates.cs | 0 .../CakeMail.RestClient.UnitTests}/Timezones.cs | 0 .../CakeMail.RestClient.UnitTests}/Triggers.cs | 0 .../CakeMail.RestClient.UnitTests}/Users.cs | 0 .../Utilities/CakeMailArrayConverter.cs | 0 .../Utilities/CakeMailDateTimeConverter.cs | 0 .../Utilities/CakeMailIntegerBooleanConverter.cs | 0 .../CakeMail.RestClient.UnitTests}/Utilities/ExtensionMethods.cs | 0 .../CakeMail.RestClient.UnitTests}/packages.config | 0 CakeMail.RestClient.sln => Source/CakeMail.RestClient.sln | 0 .../CakeMail.RestClient}/CakeMail.RestClient.csproj | 0 .../CakeMail.RestClient}/CakeMail.RestClient.nuspec | 0 .../CakeMail.RestClient}/CakeMailRestClient.cs | 0 .../CakeMail.RestClient}/Exceptions/CakeMailException.cs | 0 .../CakeMail.RestClient}/Exceptions/CakeMailPostException.cs | 0 .../CakeMail.RestClient}/Exceptions/HttpException.cs | 0 .../CakeMail.RestClient}/ICakeMailRestClient.cs | 0 .../CakeMail.RestClient}/Models/Campaign.cs | 0 .../CakeMail.RestClient}/Models/CampaignStatus.cs | 0 .../CakeMail.RestClient}/Models/CampaignsSortBy.cs | 0 .../CakeMail.RestClient}/Models/Client.cs | 0 .../CakeMail.RestClient}/Models/ClientRegistrationInfo.cs | 0 .../CakeMail.RestClient}/Models/ClientStatus.cs | 0 .../CakeMail.RestClient}/Models/ClientsSortBy.cs | 0 .../CakeMail.RestClient}/Models/Country.cs | 0 .../CakeMail.RestClient}/Models/FieldType.cs | 0 .../CakeMail.RestClient}/Models/ImportResult.cs | 0 .../CakeMail.RestClient}/Models/Link.cs | 0 .../CakeMail.RestClient}/Models/LinkStats.cs | 0 .../CakeMail.RestClient}/Models/List.cs | 0 .../CakeMail.RestClient}/Models/ListField.cs | 0 .../CakeMail.RestClient}/Models/ListMember.cs | 0 .../CakeMail.RestClient}/Models/ListMemberStatus.cs | 0 .../CakeMail.RestClient}/Models/ListMembersSortBy.cs | 0 .../CakeMail.RestClient}/Models/ListStatus.cs | 0 .../CakeMail.RestClient}/Models/ListsSortBy.cs | 0 .../CakeMail.RestClient}/Models/LogItem.cs | 0 .../CakeMail.RestClient}/Models/LogType.cs | 0 .../CakeMail.RestClient}/Models/LoginInfo.cs | 0 .../CakeMail.RestClient}/Models/Mailing.cs | 0 .../CakeMail.RestClient}/Models/MailingStatus.cs | 0 .../CakeMail.RestClient}/Models/MailingType.cs | 0 .../CakeMail.RestClient}/Models/MailingsSortBy.cs | 0 .../CakeMail.RestClient}/Models/MessageEncoding.cs | 0 .../CakeMail.RestClient}/Models/Province.cs | 0 .../CakeMail.RestClient}/Models/RawEmailMessage.cs | 0 .../CakeMail.RestClient}/Models/RelayBounceLog.cs | 0 .../CakeMail.RestClient}/Models/RelayClickLog.cs | 0 .../CakeMail.RestClient}/Models/RelayLog.cs | 0 .../CakeMail.RestClient}/Models/RelayOpenLog.cs | 0 .../CakeMail.RestClient}/Models/Segment.cs | 0 .../CakeMail.RestClient}/Models/SortDirection.cs | 0 .../CakeMail.RestClient}/Models/SuppressDomainResult.cs | 0 .../CakeMail.RestClient}/Models/SuppressEmailResult.cs | 0 .../CakeMail.RestClient}/Models/SuppressLocalPartResult.cs | 0 .../CakeMail.RestClient}/Models/SuppressedEmail.cs | 0 .../CakeMail.RestClient}/Models/Template.cs | 0 .../CakeMail.RestClient}/Models/TemplateCategory.cs | 0 .../CakeMail.RestClient}/Models/TemplateCategoryVisibility.cs | 0 .../CakeMail.RestClient}/Models/Timezone.cs | 0 .../CakeMail.RestClient}/Models/TransferEncoding.cs | 0 .../CakeMail.RestClient}/Models/Trigger.cs | 0 .../CakeMail.RestClient}/Models/TriggerAction.cs | 0 .../CakeMail.RestClient}/Models/TriggerStatus.cs | 0 .../CakeMail.RestClient}/Models/UnConfirmedClient.cs | 0 .../CakeMail.RestClient}/Models/User.cs | 0 .../CakeMail.RestClient}/Models/UserStatus.cs | 0 .../CakeMail.RestClient}/Properties/AssemblyInfo.cs | 0 .../CakeMail.RestClient}/Resources/Campaigns.cs | 0 .../CakeMail.RestClient}/Resources/Clients.cs | 0 .../CakeMail.RestClient}/Resources/Countries.cs | 0 .../CakeMail.RestClient}/Resources/Lists.cs | 0 .../CakeMail.RestClient}/Resources/Mailings.cs | 0 .../CakeMail.RestClient}/Resources/Permissions.cs | 0 .../CakeMail.RestClient}/Resources/Relays.cs | 0 .../CakeMail.RestClient}/Resources/Segments.cs | 0 .../CakeMail.RestClient}/Resources/SuppressionLists.cs | 0 .../CakeMail.RestClient}/Resources/Templates.cs | 0 .../CakeMail.RestClient}/Resources/Timezones.cs | 0 .../CakeMail.RestClient}/Resources/Triggers.cs | 0 .../CakeMail.RestClient}/Resources/Users.cs | 0 .../CakeMail.RestClient}/Utilities/CakeMailDateTimeConverter.cs | 0 .../Utilities/CakeMailIntegerBooleanConverter.cs | 0 .../CakeMail.RestClient}/Utilities/Constants.cs | 0 .../CakeMail.RestClient}/Utilities/ExtensionMethods.cs | 0 .../CakeMail.RestClient}/packages.config | 0 119 files changed, 0 insertions(+), 0 deletions(-) rename {CakeMail.RestClient.IntegrationTests => Source/CakeMail.RestClient.IntegrationTests}/App.config (100%) rename {CakeMail.RestClient.IntegrationTests => Source/CakeMail.RestClient.IntegrationTests}/CakeMail.RestClient.IntegrationTests.csproj (100%) rename {CakeMail.RestClient.IntegrationTests => Source/CakeMail.RestClient.IntegrationTests}/Campaigns.cs (100%) rename {CakeMail.RestClient.IntegrationTests => Source/CakeMail.RestClient.IntegrationTests}/Clients.cs (100%) rename {CakeMail.RestClient.IntegrationTests => Source/CakeMail.RestClient.IntegrationTests}/Countries.cs (100%) rename {CakeMail.RestClient.IntegrationTests => Source/CakeMail.RestClient.IntegrationTests}/Lists.cs (100%) rename {CakeMail.RestClient.IntegrationTests => Source/CakeMail.RestClient.IntegrationTests}/Mailings.cs (100%) rename {CakeMail.RestClient.IntegrationTests => Source/CakeMail.RestClient.IntegrationTests}/Permissions.cs (100%) rename {CakeMail.RestClient.IntegrationTests => Source/CakeMail.RestClient.IntegrationTests}/Program.cs (100%) rename {CakeMail.RestClient.IntegrationTests => Source/CakeMail.RestClient.IntegrationTests}/Properties/AssemblyInfo.cs (100%) rename {CakeMail.RestClient.IntegrationTests => Source/CakeMail.RestClient.IntegrationTests}/Relays.cs (100%) rename {CakeMail.RestClient.IntegrationTests => Source/CakeMail.RestClient.IntegrationTests}/SuppressionLists.cs (100%) rename {CakeMail.RestClient.IntegrationTests => Source/CakeMail.RestClient.IntegrationTests}/Templates.cs (100%) rename {CakeMail.RestClient.IntegrationTests => Source/CakeMail.RestClient.IntegrationTests}/Timezones.cs (100%) rename {CakeMail.RestClient.IntegrationTests => Source/CakeMail.RestClient.IntegrationTests}/Triggers.cs (100%) rename {CakeMail.RestClient.IntegrationTests => Source/CakeMail.RestClient.IntegrationTests}/Users.cs (100%) rename {CakeMail.RestClient.IntegrationTests => Source/CakeMail.RestClient.IntegrationTests}/packages.config (100%) rename {CakeMail.RestClient.UnitTests => Source/CakeMail.RestClient.UnitTests}/CakeMail.RestClient.UnitTests.csproj (100%) rename {CakeMail.RestClient.UnitTests => Source/CakeMail.RestClient.UnitTests}/CakeMailRestClientTests.cs (100%) rename {CakeMail.RestClient.UnitTests => Source/CakeMail.RestClient.UnitTests}/Campaigns.cs (100%) rename {CakeMail.RestClient.UnitTests => Source/CakeMail.RestClient.UnitTests}/Clients.cs (100%) rename {CakeMail.RestClient.UnitTests => Source/CakeMail.RestClient.UnitTests}/Countries.cs (100%) rename {CakeMail.RestClient.UnitTests => Source/CakeMail.RestClient.UnitTests}/Exceptions/CakeMailException.cs (100%) rename {CakeMail.RestClient.UnitTests => Source/CakeMail.RestClient.UnitTests}/Exceptions/CakeMailPostException.cs (100%) rename {CakeMail.RestClient.UnitTests => Source/CakeMail.RestClient.UnitTests}/Exceptions/HttpException.cs (100%) rename {CakeMail.RestClient.UnitTests => Source/CakeMail.RestClient.UnitTests}/Lists.cs (100%) rename {CakeMail.RestClient.UnitTests => Source/CakeMail.RestClient.UnitTests}/Mailings.cs (100%) rename {CakeMail.RestClient.UnitTests => Source/CakeMail.RestClient.UnitTests}/MockRestClient.cs (100%) rename {CakeMail.RestClient.UnitTests => Source/CakeMail.RestClient.UnitTests}/Permissions.cs (100%) rename {CakeMail.RestClient.UnitTests => Source/CakeMail.RestClient.UnitTests}/Properties/AssemblyInfo.cs (100%) rename {CakeMail.RestClient.UnitTests => Source/CakeMail.RestClient.UnitTests}/Relays.cs (100%) rename {CakeMail.RestClient.UnitTests => Source/CakeMail.RestClient.UnitTests}/Segments.cs (100%) rename {CakeMail.RestClient.UnitTests => Source/CakeMail.RestClient.UnitTests}/SuppressionLists.cs (100%) rename {CakeMail.RestClient.UnitTests => Source/CakeMail.RestClient.UnitTests}/Templates.cs (100%) rename {CakeMail.RestClient.UnitTests => Source/CakeMail.RestClient.UnitTests}/Timezones.cs (100%) rename {CakeMail.RestClient.UnitTests => Source/CakeMail.RestClient.UnitTests}/Triggers.cs (100%) rename {CakeMail.RestClient.UnitTests => Source/CakeMail.RestClient.UnitTests}/Users.cs (100%) rename {CakeMail.RestClient.UnitTests => Source/CakeMail.RestClient.UnitTests}/Utilities/CakeMailArrayConverter.cs (100%) rename {CakeMail.RestClient.UnitTests => Source/CakeMail.RestClient.UnitTests}/Utilities/CakeMailDateTimeConverter.cs (100%) rename {CakeMail.RestClient.UnitTests => Source/CakeMail.RestClient.UnitTests}/Utilities/CakeMailIntegerBooleanConverter.cs (100%) rename {CakeMail.RestClient.UnitTests => Source/CakeMail.RestClient.UnitTests}/Utilities/ExtensionMethods.cs (100%) rename {CakeMail.RestClient.UnitTests => Source/CakeMail.RestClient.UnitTests}/packages.config (100%) rename CakeMail.RestClient.sln => Source/CakeMail.RestClient.sln (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/CakeMail.RestClient.csproj (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/CakeMail.RestClient.nuspec (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/CakeMailRestClient.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Exceptions/CakeMailException.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Exceptions/CakeMailPostException.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Exceptions/HttpException.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/ICakeMailRestClient.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/Campaign.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/CampaignStatus.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/CampaignsSortBy.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/Client.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/ClientRegistrationInfo.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/ClientStatus.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/ClientsSortBy.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/Country.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/FieldType.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/ImportResult.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/Link.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/LinkStats.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/List.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/ListField.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/ListMember.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/ListMemberStatus.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/ListMembersSortBy.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/ListStatus.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/ListsSortBy.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/LogItem.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/LogType.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/LoginInfo.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/Mailing.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/MailingStatus.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/MailingType.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/MailingsSortBy.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/MessageEncoding.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/Province.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/RawEmailMessage.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/RelayBounceLog.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/RelayClickLog.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/RelayLog.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/RelayOpenLog.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/Segment.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/SortDirection.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/SuppressDomainResult.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/SuppressEmailResult.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/SuppressLocalPartResult.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/SuppressedEmail.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/Template.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/TemplateCategory.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/TemplateCategoryVisibility.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/Timezone.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/TransferEncoding.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/Trigger.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/TriggerAction.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/TriggerStatus.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/UnConfirmedClient.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/User.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Models/UserStatus.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Properties/AssemblyInfo.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Resources/Campaigns.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Resources/Clients.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Resources/Countries.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Resources/Lists.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Resources/Mailings.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Resources/Permissions.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Resources/Relays.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Resources/Segments.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Resources/SuppressionLists.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Resources/Templates.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Resources/Timezones.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Resources/Triggers.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Resources/Users.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Utilities/CakeMailDateTimeConverter.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Utilities/CakeMailIntegerBooleanConverter.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Utilities/Constants.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/Utilities/ExtensionMethods.cs (100%) rename {CakeMail.RestClient => Source/CakeMail.RestClient}/packages.config (100%) diff --git a/CakeMail.RestClient.IntegrationTests/App.config b/Source/CakeMail.RestClient.IntegrationTests/App.config similarity index 100% rename from CakeMail.RestClient.IntegrationTests/App.config rename to Source/CakeMail.RestClient.IntegrationTests/App.config diff --git a/CakeMail.RestClient.IntegrationTests/CakeMail.RestClient.IntegrationTests.csproj b/Source/CakeMail.RestClient.IntegrationTests/CakeMail.RestClient.IntegrationTests.csproj similarity index 100% rename from CakeMail.RestClient.IntegrationTests/CakeMail.RestClient.IntegrationTests.csproj rename to Source/CakeMail.RestClient.IntegrationTests/CakeMail.RestClient.IntegrationTests.csproj 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 100% rename from CakeMail.RestClient.IntegrationTests/Clients.cs rename to Source/CakeMail.RestClient.IntegrationTests/Clients.cs 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 100% rename from CakeMail.RestClient.IntegrationTests/Program.cs rename to Source/CakeMail.RestClient.IntegrationTests/Program.cs diff --git a/CakeMail.RestClient.IntegrationTests/Properties/AssemblyInfo.cs b/Source/CakeMail.RestClient.IntegrationTests/Properties/AssemblyInfo.cs similarity index 100% rename from CakeMail.RestClient.IntegrationTests/Properties/AssemblyInfo.cs rename to Source/CakeMail.RestClient.IntegrationTests/Properties/AssemblyInfo.cs 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/CakeMail.RestClient.IntegrationTests/packages.config b/Source/CakeMail.RestClient.IntegrationTests/packages.config similarity index 100% rename from CakeMail.RestClient.IntegrationTests/packages.config rename to Source/CakeMail.RestClient.IntegrationTests/packages.config diff --git a/CakeMail.RestClient.UnitTests/CakeMail.RestClient.UnitTests.csproj b/Source/CakeMail.RestClient.UnitTests/CakeMail.RestClient.UnitTests.csproj similarity index 100% rename from CakeMail.RestClient.UnitTests/CakeMail.RestClient.UnitTests.csproj rename to Source/CakeMail.RestClient.UnitTests/CakeMail.RestClient.UnitTests.csproj diff --git a/CakeMail.RestClient.UnitTests/CakeMailRestClientTests.cs b/Source/CakeMail.RestClient.UnitTests/CakeMailRestClientTests.cs similarity index 100% rename from CakeMail.RestClient.UnitTests/CakeMailRestClientTests.cs rename to Source/CakeMail.RestClient.UnitTests/CakeMailRestClientTests.cs diff --git a/CakeMail.RestClient.UnitTests/Campaigns.cs b/Source/CakeMail.RestClient.UnitTests/Campaigns.cs similarity index 100% rename from CakeMail.RestClient.UnitTests/Campaigns.cs rename to Source/CakeMail.RestClient.UnitTests/Campaigns.cs diff --git a/CakeMail.RestClient.UnitTests/Clients.cs b/Source/CakeMail.RestClient.UnitTests/Clients.cs similarity index 100% rename from CakeMail.RestClient.UnitTests/Clients.cs rename to Source/CakeMail.RestClient.UnitTests/Clients.cs diff --git a/CakeMail.RestClient.UnitTests/Countries.cs b/Source/CakeMail.RestClient.UnitTests/Countries.cs similarity index 100% rename from CakeMail.RestClient.UnitTests/Countries.cs rename to Source/CakeMail.RestClient.UnitTests/Countries.cs diff --git a/CakeMail.RestClient.UnitTests/Exceptions/CakeMailException.cs b/Source/CakeMail.RestClient.UnitTests/Exceptions/CakeMailException.cs similarity index 100% rename from CakeMail.RestClient.UnitTests/Exceptions/CakeMailException.cs rename to Source/CakeMail.RestClient.UnitTests/Exceptions/CakeMailException.cs diff --git a/CakeMail.RestClient.UnitTests/Exceptions/CakeMailPostException.cs b/Source/CakeMail.RestClient.UnitTests/Exceptions/CakeMailPostException.cs similarity index 100% rename from CakeMail.RestClient.UnitTests/Exceptions/CakeMailPostException.cs rename to Source/CakeMail.RestClient.UnitTests/Exceptions/CakeMailPostException.cs diff --git a/CakeMail.RestClient.UnitTests/Exceptions/HttpException.cs b/Source/CakeMail.RestClient.UnitTests/Exceptions/HttpException.cs similarity index 100% rename from CakeMail.RestClient.UnitTests/Exceptions/HttpException.cs rename to Source/CakeMail.RestClient.UnitTests/Exceptions/HttpException.cs diff --git a/CakeMail.RestClient.UnitTests/Lists.cs b/Source/CakeMail.RestClient.UnitTests/Lists.cs similarity index 100% rename from CakeMail.RestClient.UnitTests/Lists.cs rename to Source/CakeMail.RestClient.UnitTests/Lists.cs diff --git a/CakeMail.RestClient.UnitTests/Mailings.cs b/Source/CakeMail.RestClient.UnitTests/Mailings.cs similarity index 100% rename from CakeMail.RestClient.UnitTests/Mailings.cs rename to Source/CakeMail.RestClient.UnitTests/Mailings.cs diff --git a/CakeMail.RestClient.UnitTests/MockRestClient.cs b/Source/CakeMail.RestClient.UnitTests/MockRestClient.cs similarity index 100% rename from CakeMail.RestClient.UnitTests/MockRestClient.cs rename to Source/CakeMail.RestClient.UnitTests/MockRestClient.cs diff --git a/CakeMail.RestClient.UnitTests/Permissions.cs b/Source/CakeMail.RestClient.UnitTests/Permissions.cs similarity index 100% rename from CakeMail.RestClient.UnitTests/Permissions.cs rename to Source/CakeMail.RestClient.UnitTests/Permissions.cs 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/Relays.cs b/Source/CakeMail.RestClient.UnitTests/Relays.cs similarity index 100% rename from CakeMail.RestClient.UnitTests/Relays.cs rename to Source/CakeMail.RestClient.UnitTests/Relays.cs diff --git a/CakeMail.RestClient.UnitTests/Segments.cs b/Source/CakeMail.RestClient.UnitTests/Segments.cs similarity index 100% rename from CakeMail.RestClient.UnitTests/Segments.cs rename to Source/CakeMail.RestClient.UnitTests/Segments.cs diff --git a/CakeMail.RestClient.UnitTests/SuppressionLists.cs b/Source/CakeMail.RestClient.UnitTests/SuppressionLists.cs similarity index 100% rename from CakeMail.RestClient.UnitTests/SuppressionLists.cs rename to Source/CakeMail.RestClient.UnitTests/SuppressionLists.cs diff --git a/CakeMail.RestClient.UnitTests/Templates.cs b/Source/CakeMail.RestClient.UnitTests/Templates.cs similarity index 100% rename from CakeMail.RestClient.UnitTests/Templates.cs rename to Source/CakeMail.RestClient.UnitTests/Templates.cs diff --git a/CakeMail.RestClient.UnitTests/Timezones.cs b/Source/CakeMail.RestClient.UnitTests/Timezones.cs similarity index 100% rename from CakeMail.RestClient.UnitTests/Timezones.cs rename to Source/CakeMail.RestClient.UnitTests/Timezones.cs diff --git a/CakeMail.RestClient.UnitTests/Triggers.cs b/Source/CakeMail.RestClient.UnitTests/Triggers.cs similarity index 100% rename from CakeMail.RestClient.UnitTests/Triggers.cs rename to Source/CakeMail.RestClient.UnitTests/Triggers.cs diff --git a/CakeMail.RestClient.UnitTests/Users.cs b/Source/CakeMail.RestClient.UnitTests/Users.cs similarity index 100% rename from CakeMail.RestClient.UnitTests/Users.cs rename to Source/CakeMail.RestClient.UnitTests/Users.cs diff --git a/CakeMail.RestClient.UnitTests/Utilities/CakeMailArrayConverter.cs b/Source/CakeMail.RestClient.UnitTests/Utilities/CakeMailArrayConverter.cs similarity index 100% rename from CakeMail.RestClient.UnitTests/Utilities/CakeMailArrayConverter.cs rename to Source/CakeMail.RestClient.UnitTests/Utilities/CakeMailArrayConverter.cs diff --git a/CakeMail.RestClient.UnitTests/Utilities/CakeMailDateTimeConverter.cs b/Source/CakeMail.RestClient.UnitTests/Utilities/CakeMailDateTimeConverter.cs similarity index 100% rename from CakeMail.RestClient.UnitTests/Utilities/CakeMailDateTimeConverter.cs rename to Source/CakeMail.RestClient.UnitTests/Utilities/CakeMailDateTimeConverter.cs diff --git a/CakeMail.RestClient.UnitTests/Utilities/CakeMailIntegerBooleanConverter.cs b/Source/CakeMail.RestClient.UnitTests/Utilities/CakeMailIntegerBooleanConverter.cs similarity index 100% rename from CakeMail.RestClient.UnitTests/Utilities/CakeMailIntegerBooleanConverter.cs rename to Source/CakeMail.RestClient.UnitTests/Utilities/CakeMailIntegerBooleanConverter.cs diff --git a/CakeMail.RestClient.UnitTests/Utilities/ExtensionMethods.cs b/Source/CakeMail.RestClient.UnitTests/Utilities/ExtensionMethods.cs similarity index 100% rename from CakeMail.RestClient.UnitTests/Utilities/ExtensionMethods.cs rename to Source/CakeMail.RestClient.UnitTests/Utilities/ExtensionMethods.cs diff --git a/CakeMail.RestClient.UnitTests/packages.config b/Source/CakeMail.RestClient.UnitTests/packages.config similarity index 100% rename from CakeMail.RestClient.UnitTests/packages.config rename to Source/CakeMail.RestClient.UnitTests/packages.config diff --git a/CakeMail.RestClient.sln b/Source/CakeMail.RestClient.sln similarity index 100% rename from CakeMail.RestClient.sln rename to Source/CakeMail.RestClient.sln diff --git a/CakeMail.RestClient/CakeMail.RestClient.csproj b/Source/CakeMail.RestClient/CakeMail.RestClient.csproj similarity index 100% rename from CakeMail.RestClient/CakeMail.RestClient.csproj rename to Source/CakeMail.RestClient/CakeMail.RestClient.csproj diff --git a/CakeMail.RestClient/CakeMail.RestClient.nuspec b/Source/CakeMail.RestClient/CakeMail.RestClient.nuspec similarity index 100% rename from CakeMail.RestClient/CakeMail.RestClient.nuspec rename to Source/CakeMail.RestClient/CakeMail.RestClient.nuspec diff --git a/CakeMail.RestClient/CakeMailRestClient.cs b/Source/CakeMail.RestClient/CakeMailRestClient.cs similarity index 100% rename from CakeMail.RestClient/CakeMailRestClient.cs rename to Source/CakeMail.RestClient/CakeMailRestClient.cs diff --git a/CakeMail.RestClient/Exceptions/CakeMailException.cs b/Source/CakeMail.RestClient/Exceptions/CakeMailException.cs similarity index 100% rename from CakeMail.RestClient/Exceptions/CakeMailException.cs rename to Source/CakeMail.RestClient/Exceptions/CakeMailException.cs diff --git a/CakeMail.RestClient/Exceptions/CakeMailPostException.cs b/Source/CakeMail.RestClient/Exceptions/CakeMailPostException.cs similarity index 100% rename from CakeMail.RestClient/Exceptions/CakeMailPostException.cs rename to Source/CakeMail.RestClient/Exceptions/CakeMailPostException.cs diff --git a/CakeMail.RestClient/Exceptions/HttpException.cs b/Source/CakeMail.RestClient/Exceptions/HttpException.cs similarity index 100% rename from CakeMail.RestClient/Exceptions/HttpException.cs rename to Source/CakeMail.RestClient/Exceptions/HttpException.cs diff --git a/CakeMail.RestClient/ICakeMailRestClient.cs b/Source/CakeMail.RestClient/ICakeMailRestClient.cs similarity index 100% rename from CakeMail.RestClient/ICakeMailRestClient.cs rename to Source/CakeMail.RestClient/ICakeMailRestClient.cs 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 100% rename from CakeMail.RestClient/Models/Client.cs rename to Source/CakeMail.RestClient/Models/Client.cs 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 100% rename from CakeMail.RestClient/Models/List.cs rename to Source/CakeMail.RestClient/Models/List.cs 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 100% rename from CakeMail.RestClient/Models/Mailing.cs rename to Source/CakeMail.RestClient/Models/Mailing.cs 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 100% rename from CakeMail.RestClient/Models/User.cs rename to Source/CakeMail.RestClient/Models/User.cs 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/CakeMail.RestClient/Properties/AssemblyInfo.cs b/Source/CakeMail.RestClient/Properties/AssemblyInfo.cs similarity index 100% rename from CakeMail.RestClient/Properties/AssemblyInfo.cs rename to Source/CakeMail.RestClient/Properties/AssemblyInfo.cs diff --git a/CakeMail.RestClient/Resources/Campaigns.cs b/Source/CakeMail.RestClient/Resources/Campaigns.cs similarity index 100% rename from CakeMail.RestClient/Resources/Campaigns.cs rename to Source/CakeMail.RestClient/Resources/Campaigns.cs diff --git a/CakeMail.RestClient/Resources/Clients.cs b/Source/CakeMail.RestClient/Resources/Clients.cs similarity index 100% rename from CakeMail.RestClient/Resources/Clients.cs rename to Source/CakeMail.RestClient/Resources/Clients.cs diff --git a/CakeMail.RestClient/Resources/Countries.cs b/Source/CakeMail.RestClient/Resources/Countries.cs similarity index 100% rename from CakeMail.RestClient/Resources/Countries.cs rename to Source/CakeMail.RestClient/Resources/Countries.cs diff --git a/CakeMail.RestClient/Resources/Lists.cs b/Source/CakeMail.RestClient/Resources/Lists.cs similarity index 100% rename from CakeMail.RestClient/Resources/Lists.cs rename to Source/CakeMail.RestClient/Resources/Lists.cs diff --git a/CakeMail.RestClient/Resources/Mailings.cs b/Source/CakeMail.RestClient/Resources/Mailings.cs similarity index 100% rename from CakeMail.RestClient/Resources/Mailings.cs rename to Source/CakeMail.RestClient/Resources/Mailings.cs diff --git a/CakeMail.RestClient/Resources/Permissions.cs b/Source/CakeMail.RestClient/Resources/Permissions.cs similarity index 100% rename from CakeMail.RestClient/Resources/Permissions.cs rename to Source/CakeMail.RestClient/Resources/Permissions.cs diff --git a/CakeMail.RestClient/Resources/Relays.cs b/Source/CakeMail.RestClient/Resources/Relays.cs similarity index 100% rename from CakeMail.RestClient/Resources/Relays.cs rename to Source/CakeMail.RestClient/Resources/Relays.cs diff --git a/CakeMail.RestClient/Resources/Segments.cs b/Source/CakeMail.RestClient/Resources/Segments.cs similarity index 100% rename from CakeMail.RestClient/Resources/Segments.cs rename to Source/CakeMail.RestClient/Resources/Segments.cs diff --git a/CakeMail.RestClient/Resources/SuppressionLists.cs b/Source/CakeMail.RestClient/Resources/SuppressionLists.cs similarity index 100% rename from CakeMail.RestClient/Resources/SuppressionLists.cs rename to Source/CakeMail.RestClient/Resources/SuppressionLists.cs diff --git a/CakeMail.RestClient/Resources/Templates.cs b/Source/CakeMail.RestClient/Resources/Templates.cs similarity index 100% rename from CakeMail.RestClient/Resources/Templates.cs rename to Source/CakeMail.RestClient/Resources/Templates.cs diff --git a/CakeMail.RestClient/Resources/Timezones.cs b/Source/CakeMail.RestClient/Resources/Timezones.cs similarity index 100% rename from CakeMail.RestClient/Resources/Timezones.cs rename to Source/CakeMail.RestClient/Resources/Timezones.cs diff --git a/CakeMail.RestClient/Resources/Triggers.cs b/Source/CakeMail.RestClient/Resources/Triggers.cs similarity index 100% rename from CakeMail.RestClient/Resources/Triggers.cs rename to Source/CakeMail.RestClient/Resources/Triggers.cs diff --git a/CakeMail.RestClient/Resources/Users.cs b/Source/CakeMail.RestClient/Resources/Users.cs similarity index 100% rename from CakeMail.RestClient/Resources/Users.cs rename to Source/CakeMail.RestClient/Resources/Users.cs diff --git a/CakeMail.RestClient/Utilities/CakeMailDateTimeConverter.cs b/Source/CakeMail.RestClient/Utilities/CakeMailDateTimeConverter.cs similarity index 100% rename from CakeMail.RestClient/Utilities/CakeMailDateTimeConverter.cs rename to Source/CakeMail.RestClient/Utilities/CakeMailDateTimeConverter.cs diff --git a/CakeMail.RestClient/Utilities/CakeMailIntegerBooleanConverter.cs b/Source/CakeMail.RestClient/Utilities/CakeMailIntegerBooleanConverter.cs similarity index 100% rename from CakeMail.RestClient/Utilities/CakeMailIntegerBooleanConverter.cs rename to Source/CakeMail.RestClient/Utilities/CakeMailIntegerBooleanConverter.cs diff --git a/CakeMail.RestClient/Utilities/Constants.cs b/Source/CakeMail.RestClient/Utilities/Constants.cs similarity index 100% rename from CakeMail.RestClient/Utilities/Constants.cs rename to Source/CakeMail.RestClient/Utilities/Constants.cs diff --git a/CakeMail.RestClient/Utilities/ExtensionMethods.cs b/Source/CakeMail.RestClient/Utilities/ExtensionMethods.cs similarity index 100% rename from CakeMail.RestClient/Utilities/ExtensionMethods.cs rename to Source/CakeMail.RestClient/Utilities/ExtensionMethods.cs diff --git a/CakeMail.RestClient/packages.config b/Source/CakeMail.RestClient/packages.config similarity index 100% rename from CakeMail.RestClient/packages.config rename to Source/CakeMail.RestClient/packages.config From 7a830310da0427ff78557cb9b7f4c0f294f73e95 Mon Sep 17 00:00:00 2001 From: Jeremie Desautels Date: Fri, 18 Nov 2016 10:57:18 -0600 Subject: [PATCH 02/24] Update gitignore --- .gitignore | 116 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 92 insertions(+), 24 deletions(-) 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 From 8cb65dd07b5fd35b0f5116ca5ab7b9d04d9f1960 Mon Sep 17 00:00:00 2001 From: Jeremie Desautels Date: Fri, 18 Nov 2016 11:01:57 -0600 Subject: [PATCH 03/24] Build script --- Code Coverage Report.bat | 26 ------ GitReleaseManager.yaml | 27 ++++++ GitVersion.yml | 7 ++ appveyor.yml | 108 +++++----------------- build.ps1 | 189 +++++++++++++++++++++++++++++++++++++++ tools/packages.config | 4 + 6 files changed, 248 insertions(+), 113 deletions(-) delete mode 100644 Code Coverage Report.bat create mode 100644 GitReleaseManager.yaml create mode 100644 GitVersion.yml create mode 100644 build.ps1 create mode 100644 tools/packages.config 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..2533fdf --- /dev/null +++ b/GitVersion.yml @@ -0,0 +1,7 @@ +mode: ContinuousDelivery +branches: + dev(elop)?(ment)?$: + mode: ContinuousDeployment + tag: pre +ignore: + sha: [] diff --git a/appveyor.yml b/appveyor.yml index b5805ca..4cb0012 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,90 +1,24 @@ -# configuration for "master" branch -- - branches: - only: - - master - configuration: Release - platform: Any CPU - skip_tags: true - image: Visual Studio 2015 - version: 5.1.{build} - assembly_info: - patch: true - file: '**\AssemblyInfo.*' - assembly_version: '{version}' - assembly_file_version: '{version}' - assembly_informational_version: '{version}' - nuget: - account_feed: true - project_feed: true - disable_publish_on_pr: true - environment: - COVERALLS_REPO_TOKEN: - secure: UFzWya6z1lSVM9ns9TIhin52+NW1NkH6lov5kRm91AWnK83utbXWDlUwtnXeeshJ - build: - parallel: true - project: CakeMail.RestClient.sln - publish_nuget: true - verbosity: minimal - before_build: - - nuget restore - test_script: - - packages\OpenCover.4.6.519\tools\OpenCover.Console.exe -returntargetcode -register:user -target:"vstest.console.exe" -targetargs:"/logger:Appveyor ""CakeMail.RestClient.UnitTests\bin\%configuration%\CakeMail.RestClient.UnitTests.dll""" -filter:"+[CakeMail.RestClient]* -[CakeMail.RestClient]CakeMail.RestClient.Models.* -[CakeMail.RestClient]CakeMail.RestClient.Properties.*" -excludebyattribute:"*.ExcludeFromCodeCoverage*" -hideskipped:"All" -output:coverage.xml - after_test: - - packages\coveralls.io.1.3.4\tools\coveralls.net.exe --opencover coverage.xml - notifications: - - provider: Email - to: - - desautelsj@hotmail.com - subject: CakeMail.RestClient Build - on_build_success: true - on_build_failure: true - on_build_status_changed: false - deploy: - provider: NuGet - api_key: - secure: TtNPR7FUOtryJtreq842P15PwOPdYKkGFjk3F7yfWCAjhMJx8l8Vx6b0FfKq7E+o - artifact: /.*\.nupkg/ +# Build script +init: + - git config --global core.autocrlf true +# Build script +build_script: + - ps: .\build.ps1 -Target "AppVeyor" +# Tests +test: off -# "fall back" configuration for all other branches -# no "branches" section defined -- - configuration: Release - platform: Any CPU - skip_tags: true - image: Visual Studio 2015 - version: 5.1.{build}-pre - assembly_info: - patch: true - file: '**\AssemblyInfo.*' - assembly_version: '{version}' - assembly_file_version: '{version}' - assembly_informational_version: '{version}' - nuget: - account_feed: true - project_feed: true - disable_publish_on_pr: true - environment: - COVERALLS_REPO_TOKEN: - secure: UFzWya6z1lSVM9ns9TIhin52+NW1NkH6lov5kRm91AWnK83utbXWDlUwtnXeeshJ - build: - parallel: true - project: CakeMail.RestClient.sln - publish_nuget: true - verbosity: minimal - before_build: - - nuget restore - test_script: - - packages\OpenCover.4.6.519\tools\OpenCover.Console.exe -returntargetcode -register:user -target:"vstest.console.exe" -targetargs:"/logger:Appveyor ""CakeMail.RestClient.UnitTests\bin\%configuration%\CakeMail.RestClient.UnitTests.dll""" -filter:"+[CakeMail.RestClient]* -[CakeMail.RestClient]CakeMail.RestClient.Models.* -[CakeMail.RestClient]CakeMail.RestClient.Properties.*" -excludebyattribute:"*.ExcludeFromCodeCoverage*" -hideskipped:"All" -output:coverage.xml - after_test: - - packages\coveralls.io.1.3.4\tools\coveralls.net.exe --opencover coverage.xml - notifications: - - provider: Email - to: - - desautelsj@hotmail.com - subject: CakeMail.RestClient Build - on_build_success: false - on_build_failure: false - on_build_status_changed: true +# Branches to build +branches: + # Whitelist + only: + - develop + - master + - /release/.*/ + - /hotfix/.*/ + +# Build cache +cache: +- Source\packages -> Source\**\packages.config +- tools -> build.cake, tools\packages.config diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..44de579 --- /dev/null +++ b/build.ps1 @@ -0,0 +1,189 @@ +########################################################################## +# This is the Cake bootstrapper script for PowerShell. +# This file was downloaded from https://github.com/cake-build/resources +# Feel free to change this file to fit your needs. +########################################################################## + +<# + +.SYNOPSIS +This is a Powershell script to bootstrap a Cake build. + +.DESCRIPTION +This Powershell script will download NuGet if missing, restore NuGet tools (including Cake) +and execute your Cake build script with the parameters you provide. + +.PARAMETER Script +The build script to execute. +.PARAMETER Target +The build script target to run. +.PARAMETER Configuration +The build configuration to use. +.PARAMETER Verbosity +Specifies the amount of information to be displayed. +.PARAMETER Experimental +Tells Cake to use the latest Roslyn release. +.PARAMETER WhatIf +Performs a dry run of the build script. +No tasks will be executed. +.PARAMETER Mono +Tells Cake to use the Mono scripting engine. +.PARAMETER SkipToolPackageRestore +Skips restoring of packages. +.PARAMETER ScriptArgs +Remaining arguments are added here. + +.LINK +http://cakebuild.net + +#> + +[CmdletBinding()] +Param( + [string]$Script = "build.cake", + [string]$Target = "Default", + [ValidateSet("Release", "Debug")] + [string]$Configuration = "Release", + [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] + [string]$Verbosity = "Verbose", + [switch]$Experimental, + [Alias("DryRun","Noop")] + [switch]$WhatIf, + [switch]$Mono, + [switch]$SkipToolPackageRestore, + [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] + [string[]]$ScriptArgs +) + +[Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null +function MD5HashFile([string] $filePath) +{ + if ([string]::IsNullOrEmpty($filePath) -or !(Test-Path $filePath -PathType Leaf)) + { + return $null + } + + [System.IO.Stream] $file = $null; + [System.Security.Cryptography.MD5] $md5 = $null; + try + { + $md5 = [System.Security.Cryptography.MD5]::Create() + $file = [System.IO.File]::OpenRead($filePath) + return [System.BitConverter]::ToString($md5.ComputeHash($file)) + } + finally + { + if ($file -ne $null) + { + $file.Dispose() + } + } +} + +Write-Host "Preparing to run build script..." + +if(!$PSScriptRoot){ + $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent +} + +$TOOLS_DIR = Join-Path $PSScriptRoot "tools" +$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe" +$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe" +$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" +$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config" +$PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum" + +# Should we use mono? +$UseMono = ""; +if($Mono.IsPresent) { + Write-Verbose -Message "Using the Mono based scripting engine." + $UseMono = "-mono" +} + +# Should we use the new Roslyn? +$UseExperimental = ""; +if($Experimental.IsPresent -and !($Mono.IsPresent)) { + Write-Verbose -Message "Using experimental version of Roslyn." + $UseExperimental = "-experimental" +} + +# Is this a dry run? +$UseDryRun = ""; +if($WhatIf.IsPresent) { + $UseDryRun = "-dryrun" +} + +# Make sure tools folder exists +if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) { + Write-Verbose -Message "Creating tools directory..." + New-Item -Path $TOOLS_DIR -Type directory | out-null +} + +# Make sure that packages.config exist. +if (!(Test-Path $PACKAGES_CONFIG)) { + Write-Verbose -Message "Downloading packages.config..." + try { (New-Object System.Net.WebClient).DownloadFile("http://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) } catch { + Throw "Could not download packages.config." + } +} + +# Try find NuGet.exe in path if not exists +if (!(Test-Path $NUGET_EXE)) { + Write-Verbose -Message "Trying to find nuget.exe in PATH..." + $existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_) } + $NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1 + if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) { + Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)." + $NUGET_EXE = $NUGET_EXE_IN_PATH.FullName + } +} + +# Try download NuGet.exe if not exists +if (!(Test-Path $NUGET_EXE)) { + Write-Verbose -Message "Downloading NuGet.exe..." + try { + (New-Object System.Net.WebClient).DownloadFile($NUGET_URL, $NUGET_EXE) + } catch { + Throw "Could not download NuGet.exe." + } +} + +# Save nuget.exe path to environment to be available to child processed +$ENV:NUGET_EXE = $NUGET_EXE + +# Restore tools from NuGet? +if(-Not $SkipToolPackageRestore.IsPresent) { + Push-Location + Set-Location $TOOLS_DIR + + # Check for changes in packages.config and remove installed tools if true. + [string] $md5Hash = MD5HashFile($PACKAGES_CONFIG) + if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or + ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) { + Write-Verbose -Message "Missing or changed package.config hash..." + Remove-Item * -Recurse -Exclude packages.config,nuget.exe + } + + Write-Verbose -Message "Restoring tools from NuGet..." + $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`"" + + if ($LASTEXITCODE -ne 0) { + Throw "An error occured while restoring NuGet tools." + } + else + { + $md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII" + } + Write-Verbose -Message ($NuGetOutput | out-string) + Pop-Location +} + +# Make sure that Cake has been installed. +if (!(Test-Path $CAKE_EXE)) { + Throw "Could not find Cake.exe at $CAKE_EXE" +} + +# Start Cake +Write-Host "Running build script..." +Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental $ScriptArgs" +exit $LASTEXITCODE \ No newline at end of file diff --git a/tools/packages.config b/tools/packages.config new file mode 100644 index 0000000..85fc75c --- /dev/null +++ b/tools/packages.config @@ -0,0 +1,4 @@ + + + + From 676bec49bf391afc3f477d758a6fc5ec00190384 Mon Sep 17 00:00:00 2001 From: Jeremie Desautels Date: Fri, 18 Nov 2016 11:10:25 -0600 Subject: [PATCH 04/24] Move nuspec file to its own folder --- .nuget/packages.config | 6 ------ Source/CakeMail.RestClient.sln | 11 ++--------- .../CakeMail.RestClient.nuspec | 0 3 files changed, 2 insertions(+), 15 deletions(-) delete mode 100644 .nuget/packages.config rename {Source/CakeMail.RestClient => nuspec}/CakeMail.RestClient.nuspec (100%) 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/Source/CakeMail.RestClient.sln b/Source/CakeMail.RestClient.sln index 0f63c9b..49099f5 100644 --- a/Source/CakeMail.RestClient.sln +++ b/Source/CakeMail.RestClient.sln @@ -1,13 +1,11 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.25123.0 +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 - .editorconfig = .editorconfig - appveyor.yml = appveyor.yml - CakeMail.RestClient\CakeMail.RestClient.nuspec = CakeMail.RestClient\CakeMail.RestClient.nuspec + ..\nuspec\CakeMail.RestClient.nuspec = ..\nuspec\CakeMail.RestClient.nuspec LICENSE = LICENSE README.md = README.md EndProjectSection @@ -18,11 +16,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CakeMail.RestClient", "Cake 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}" diff --git a/Source/CakeMail.RestClient/CakeMail.RestClient.nuspec b/nuspec/CakeMail.RestClient.nuspec similarity index 100% rename from Source/CakeMail.RestClient/CakeMail.RestClient.nuspec rename to nuspec/CakeMail.RestClient.nuspec From d5b4ddba44e8cb87c9c0fc5ee0a9980a40b3c673 Mon Sep 17 00:00:00 2001 From: Jeremie Desautels Date: Fri, 18 Nov 2016 11:17:56 -0600 Subject: [PATCH 05/24] Improve nuspec --- Source/CakeMail.RestClient.sln | 4 +- nuspec/CakeMail.RestClient.nuspec | 61 +++++++++++++++++++++++++------ 2 files changed, 52 insertions(+), 13 deletions(-) diff --git a/Source/CakeMail.RestClient.sln b/Source/CakeMail.RestClient.sln index 49099f5..401948b 100644 --- a/Source/CakeMail.RestClient.sln +++ b/Source/CakeMail.RestClient.sln @@ -10,11 +10,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution README.md = README.md EndProjectSection EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{F7E19221-12B8-4C6E-B87A-167A1E95EBA1}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Source", "Source", "{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}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{9D4FE070-9A1E-4746-BD77-5D81D7FF21FF}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CakeMail.RestClient.IntegrationTests", "CakeMail.RestClient.IntegrationTests\CakeMail.RestClient.IntegrationTests.csproj", "{677D93C3-10C8-47AC-B196-60CA28F57A84}" EndProject diff --git a/nuspec/CakeMail.RestClient.nuspec b/nuspec/CakeMail.RestClient.nuspec index 2029261..ecdf4eb 100644 --- a/nuspec/CakeMail.RestClient.nuspec +++ b/nuspec/CakeMail.RestClient.nuspec @@ -1,24 +1,63 @@ - $id$ - 5.1.0 + CakeMail.RestClient + 0.0.0 $title$ - $author$ - $author$ + Jeremie Desautels + Jeremie Desautels + Strongly typed library for CakeMail's API + CakeMail.RestClient is a .NET wrapper for the CakeMail API 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 + Copyright (c) Jeremie Desautels and contributors + en-US CakeMail API REST - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From ea1d002489b2cb311e253855527974c83282a1ad Mon Sep 17 00:00:00 2001 From: Jeremie Desautels Date: Fri, 18 Nov 2016 14:47:05 -0600 Subject: [PATCH 06/24] #27 Convert cproj to xproj --- Source/CakeMail.RestClient.ruleset | 79 ++++++++++ Source/CakeMail.RestClient.sln | 14 +- .../CakeMail.RestClient.csproj | 143 ------------------ .../CakeMail.RestClient.xproj | 21 +++ Source/CakeMail.RestClient/packages.config | 5 - Source/CakeMail.RestClient/project.json | 106 +++++++++++++ Source/stylecop.json | 34 +++++ 7 files changed, 247 insertions(+), 155 deletions(-) create mode 100644 Source/CakeMail.RestClient.ruleset delete mode 100644 Source/CakeMail.RestClient/CakeMail.RestClient.csproj create mode 100644 Source/CakeMail.RestClient/CakeMail.RestClient.xproj delete mode 100644 Source/CakeMail.RestClient/packages.config create mode 100644 Source/CakeMail.RestClient/project.json create mode 100644 Source/stylecop.json 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 index 401948b..fb5f73a 100644 --- a/Source/CakeMail.RestClient.sln +++ b/Source/CakeMail.RestClient.sln @@ -12,24 +12,20 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Source", "Source", "{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("{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 +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "CakeMail.RestClient", "CakeMail.RestClient\CakeMail.RestClient.xproj", "{DBEFB5D8-8E24-4152-8EFD-EF153FC3A753}" +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 @@ -38,13 +34,17 @@ Global {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 + {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 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} + {DBEFB5D8-8E24-4152-8EFD-EF153FC3A753} = {F7E19221-12B8-4C6E-B87A-167A1E95EBA1} EndGlobalSection EndGlobal diff --git a/Source/CakeMail.RestClient/CakeMail.RestClient.csproj b/Source/CakeMail.RestClient/CakeMail.RestClient.csproj deleted file mode 100644 index 9922c67..0000000 --- a/Source/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/Source/CakeMail.RestClient/CakeMail.RestClient.xproj b/Source/CakeMail.RestClient/CakeMail.RestClient.xproj new file mode 100644 index 0000000..82c63d6 --- /dev/null +++ b/Source/CakeMail.RestClient/CakeMail.RestClient.xproj @@ -0,0 +1,21 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + dbefb5d8-8e24-4152-8efd-ef153fc3a753 + CakeMail.RestClient2 + .\obj + .\bin\ + v4.5.2 + + + + 2.0 + + + diff --git a/Source/CakeMail.RestClient/packages.config b/Source/CakeMail.RestClient/packages.config deleted file mode 100644 index ef6a3d4..0000000 --- a/Source/CakeMail.RestClient/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/Source/CakeMail.RestClient/project.json b/Source/CakeMail.RestClient/project.json new file mode 100644 index 0000000..051e0fa --- /dev/null +++ b/Source/CakeMail.RestClient/project.json @@ -0,0 +1,106 @@ +{ + "buildOptions": { + "emitEntryPoint": false, + "xmlDoc": true, + "platform": "anycpu", + "additionalArguments": [ + "/ruleset:../CakeMail.RestClient.ruleset", + "/additionalfile:../stylecop.json" + ], + "compile": { + } + }, + "configurations": { + "Release": { + "buildOptions": { + "warningsAsErrors": false + } + } + }, + "dependencies": { + "StyleCop.Analyzers": { + "version": "1.0.0", + "type": "build" + } + }, + "frameworks": { + "netstandard1.6": { + "buildOptions": { + "define": [ "NETSTANDARD", "NETSTANDARD16" ] + }, + "imports": "dnxcore50", + "dependencies": { + "NETStandard.Library": "1.6.1", + "Newtonsoft.Json": "9.0.1", + "System.ComponentModel.Primitives": "4.3.0", + "System.Reflection.TypeExtensions": "4.3.0", + "System.Runtime.Serialization.Primitives": "4.3.0" + } + }, + "netstandard1.3": { + "buildOptions": { + "define": [ "NETSTANDARD", "NETSTANDARD13" ] + }, + "imports": "dnxcore50", + "dependencies": { + "NETStandard.Library": "1.6.1", + "Newtonsoft.Json": "9.0.1", + "System.ComponentModel.Primitives": "4.3.0", + "System.Reflection.TypeExtensions": "4.1.0", + "System.Runtime.Serialization.Primitives": "4.3.0" + } + }, + "net452": { + "buildOptions": { + "define": [ "NET452" ] + }, + "dependencies": { + "Newtonsoft.Json": "9.0.1", + "System.Net.Http": "4.0.0" + }, + "frameworkAssemblies": { + "System.Runtime.Serialization": "4.0.0" + } + }, + "net46": { + "buildOptions": { + "define": [ "NET46" ] + }, + "dependencies": { + "Newtonsoft.Json": "9.0.1", + "System.Net.Http": "4.0.0", + "System.Reflection.TypeExtensions": "4.3.0" + }, + "frameworkAssemblies": { + "System.Runtime.Serialization": "4.0.0" + } + }, + "net461": { + "buildOptions": { + "define": [ "NET461" ] + }, + "dependencies": { + "Newtonsoft.Json": "9.0.1", + "System.Net.Http": "4.0.0", + "System.Reflection.TypeExtensions": "4.3.0" + }, + "frameworkAssemblies": { + "System.Runtime.Serialization": "4.0.0" + } + }, + "net462": { + "buildOptions": { + "define": [ "NET462" ] + }, + "dependencies": { + "Newtonsoft.Json": "9.0.1", + "System.Net.Http": "4.0.0", + "System.Reflection.TypeExtensions": "4.3.0" + }, + "frameworkAssemblies": { + "System.Runtime.Serialization": "4.0.0" + } + } + }, + "version": "1.0.0-*" +} diff --git a/Source/stylecop.json b/Source/stylecop.json new file mode 100644 index 0000000..6dcaec6 --- /dev/null +++ b/Source/stylecop.json @@ -0,0 +1,34 @@ +{ + "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", + "settings": { + "indentation": { + "useTabs": true, + "indentationSize": 4, + "tabSize": 4 + }, + "documentationRules": { + "documentExposedElements": true, + "documentInternalElements": false, + "documentPrivateElements": false, + "documentInterfaces": true, + "documentPrivateFields": false + }, + "layoutRules": { + "newlineAtEndOfFile": "require" + }, + "maintainabilityRules": { + }, + "orderingRules": { + "usingDirectivesPlacement": "outsideNamespace", + "systemUsingDirectivesFirst": false, + "elementOrder": [ + "kind", + "accessibility", + "constant", + "static", + "readonly" + ] + + } + } +} From 550e769471187fb4b39c0cd8d81bc2f73a8ead3e Mon Sep 17 00:00:00 2001 From: Jeremie Desautels Date: Fri, 18 Nov 2016 14:51:47 -0600 Subject: [PATCH 07/24] #27 Changes necessary due to NETSTANDARD. Also fix some issues highlighted by StyleCop. --- .../Exceptions/CakeMailException.cs | 32 +++-------------- .../Exceptions/CakeMailPostException.cs | 33 ----------------- .../Exceptions/HttpException.cs | 36 ------------------- .../ICakeMailRestClient.cs | 9 ++--- Source/CakeMail.RestClient/Models/List.cs | 8 ++--- Source/CakeMail.RestClient/Models/Mailing.cs | 4 +-- Source/CakeMail.RestClient/Models/User.cs | 6 ++-- .../Properties/AssemblyInfo.cs | 6 ++-- .../CakeMail.RestClient/Resources/Clients.cs | 20 +++++------ Source/CakeMail.RestClient/Resources/Lists.cs | 3 ++ .../CakeMail.RestClient/Resources/Mailings.cs | 2 +- .../Resources/Permissions.cs | 1 + .../CakeMail.RestClient/Resources/Segments.cs | 12 +++---- .../Resources/SuppressionLists.cs | 6 ++++ .../Resources/Templates.cs | 5 +++ Source/CakeMail.RestClient/Resources/Users.cs | 2 +- .../Utilities/ExtensionMethods.cs | 35 +++++++++--------- 17 files changed, 68 insertions(+), 152 deletions(-) diff --git a/Source/CakeMail.RestClient/Exceptions/CakeMailException.cs b/Source/CakeMail.RestClient/Exceptions/CakeMailException.cs index 07f78f5..91c059e 100644 --- a/Source/CakeMail.RestClient/Exceptions/CakeMailException.cs +++ b/Source/CakeMail.RestClient/Exceptions/CakeMailException.cs @@ -1,6 +1,4 @@ using System; -using System.Runtime.Serialization; -using System.Security.Permissions; namespace CakeMail.RestClient.Exceptions { @@ -8,8 +6,11 @@ namespace CakeMail.RestClient.Exceptions /// This class represents a generic CakeMail error. All other exceptions thrown by /// the CakeMail API subclass this exception /// - [Serializable] +#if NETSTANDARD + public class CakeMailException : Exception +#else public class CakeMailException : ApplicationException +#endif { /// /// Initializes a new instance of the class. @@ -29,30 +30,5 @@ 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/Source/CakeMail.RestClient/Exceptions/CakeMailPostException.cs b/Source/CakeMail.RestClient/Exceptions/CakeMailPostException.cs index 5e6f8d9..a712798 100644 --- a/Source/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/Source/CakeMail.RestClient/Exceptions/HttpException.cs b/Source/CakeMail.RestClient/Exceptions/HttpException.cs index f55018d..7cc9fd0 100644 --- a/Source/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,7 +8,6 @@ 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 { /// @@ -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/Source/CakeMail.RestClient/ICakeMailRestClient.cs b/Source/CakeMail.RestClient/ICakeMailRestClient.cs index 8412833..a261216 100644 --- a/Source/CakeMail.RestClient/ICakeMailRestClient.cs +++ b/Source/CakeMail.RestClient/ICakeMailRestClient.cs @@ -9,18 +9,13 @@ 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 /// string ApiKey { get; } - /// - /// The web proxy - /// - IWebProxy Proxy { get; } - /// /// The user agent /// @@ -50,4 +45,4 @@ interface ICakeMailRestClient Templates Templates { get; } Triggers Triggers { get; } } -} \ No newline at end of file +} diff --git a/Source/CakeMail.RestClient/Models/List.cs b/Source/CakeMail.RestClient/Models/List.cs index c755cb2..9861d64 100644 --- a/Source/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/Source/CakeMail.RestClient/Models/Mailing.cs b/Source/CakeMail.RestClient/Models/Mailing.cs index fa230c5..6cf6c2a 100644 --- a/Source/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/Source/CakeMail.RestClient/Models/User.cs b/Source/CakeMail.RestClient/Models/User.cs index 6dda299..fe1e4cb 100644 --- a/Source/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/Source/CakeMail.RestClient/Properties/AssemblyInfo.cs b/Source/CakeMail.RestClient/Properties/AssemblyInfo.cs index fbc4195..146a640 100644 --- a/Source/CakeMail.RestClient/Properties/AssemblyInfo.cs +++ b/Source/CakeMail.RestClient/Properties/AssemblyInfo.cs @@ -1,6 +1,6 @@ using System.Reflection; -// General Information about an assembly is controlled through the following +// 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")] @@ -15,11 +15,11 @@ // Version information for an assembly consists of the following four values: // // Major Version -// Minor Version +// Minor Version // Build Number // Revision // -// You can specify all the values or you can default the Build and Revision Numbers +// 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")] diff --git a/Source/CakeMail.RestClient/Resources/Clients.cs b/Source/CakeMail.RestClient/Resources/Clients.cs index bfe84ce..60a1fcb 100644 --- a/Source/CakeMail.RestClient/Resources/Clients.cs +++ b/Source/CakeMail.RestClient/Resources/Clients.cs @@ -86,16 +86,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,16 +104,16 @@ 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); diff --git a/Source/CakeMail.RestClient/Resources/Lists.cs b/Source/CakeMail.RestClient/Resources/Lists.cs index e2ca92b..4beafaa 100644 --- a/Source/CakeMail.RestClient/Resources/Lists.cs +++ b/Source/CakeMail.RestClient/Resources/Lists.cs @@ -383,6 +383,7 @@ public Task SubscribeAsync(string userKey, long listId, string email, bool else parameters.Add(new KeyValuePair(string.Format("data[{0}]", customField.Key), customField.Value)); } } + if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); @@ -426,6 +427,7 @@ public Task> ImportAsync(string userKey, long listId, } } } + if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); return _cakeMailRestClient.ExecuteArrayRequestAsync(path, parameters, null, cancellationToken); @@ -616,6 +618,7 @@ public Task UpdateMemberAsync(string userKey, long listId, long listMember else parameters.Add(new KeyValuePair(string.Format("data[{0}]", customField.Key), customField.Value)); } } + if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); diff --git a/Source/CakeMail.RestClient/Resources/Mailings.cs b/Source/CakeMail.RestClient/Resources/Mailings.cs index 0830bdd..77222a0 100644 --- a/Source/CakeMail.RestClient/Resources/Mailings.cs +++ b/Source/CakeMail.RestClient/Resources/Mailings.cs @@ -444,7 +444,7 @@ public Task ResumeAsync(string userKey, long mailingId, long? clientId = n /// The cancellation token /// An enumeration of log items matching the filter criteria /// - /// CakeMail throws an exception if you attempt to retrieve the logs for a mailing that hasn't been sent. + /// CakeMail throws an exception if you attempt to retrieve the logs for a mailing that hasn't been sent. /// The current error message is cryptic: Table 'api_cake_logs.mailing_xxxxxxx_big' doesn't exist. /// I was assured in May 2015 that they will improve this message to make it more informative. /// diff --git a/Source/CakeMail.RestClient/Resources/Permissions.cs b/Source/CakeMail.RestClient/Resources/Permissions.cs index be894ee..247e3c0 100644 --- a/Source/CakeMail.RestClient/Resources/Permissions.cs +++ b/Source/CakeMail.RestClient/Resources/Permissions.cs @@ -68,6 +68,7 @@ public Task SetUserPermissionsAsync(string userKey, long userId, IEnumerab { parameters.Add(new KeyValuePair(string.Format("permission[{0}]", item.Index), item.Name)); } + if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); diff --git a/Source/CakeMail.RestClient/Resources/Segments.cs b/Source/CakeMail.RestClient/Resources/Segments.cs index 568fb7d..257a7db 100644 --- a/Source/CakeMail.RestClient/Resources/Segments.cs +++ b/Source/CakeMail.RestClient/Resources/Segments.cs @@ -35,12 +35,12 @@ public Segments(CakeMailRestClient cakeMailRestClient) /// The cancellation token /// ID of the new segment /// - /// Here is what I have discovered about the query: - /// 1) the entire query must be surrounded by parenthesis: (...your query...) - /// 2) field names must be surrounded with the 'special' quote: `yourfieldname`. On my US english keyboard, this 'special quote is the key directly above the 'Tab' and to the left of the '1'. - /// 3) The percent sign is the wilcard - /// Here's an example: (`email` LIKE "a%") - /// + /// Here is what I have discovered about the query: + /// 1) the entire query must be surrounded by parenthesis: (...your query...) + /// 2) field names must be surrounded with the 'special' quote: `yourfieldname`. On my US english keyboard, this 'special' quote is the key directly above the 'Tab' and to the left of the '1'. + /// 3) The percent sign is the wilcard + /// Here's an example: (`email` LIKE "a%") + /// public Task CreateAsync(string userKey, long listId, string name, string query = null, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { string path = "/List/CreateSublist/"; diff --git a/Source/CakeMail.RestClient/Resources/SuppressionLists.cs b/Source/CakeMail.RestClient/Resources/SuppressionLists.cs index a22f31e..c842362 100644 --- a/Source/CakeMail.RestClient/Resources/SuppressionLists.cs +++ b/Source/CakeMail.RestClient/Resources/SuppressionLists.cs @@ -49,6 +49,7 @@ public Task> AddEmailAddressesAsync(string user parameters.Add(new KeyValuePair(string.Format("email[{0}]", item.Index), item.Email)); } } + if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); return _cakeMailRestClient.ExecuteArrayRequestAsync(path, parameters, null, cancellationToken); @@ -77,6 +78,7 @@ public Task> AddDomainsAsync(string userKey, I parameters.Add(new KeyValuePair(string.Format("domain[{0}]", item.Index), item.Domain)); } } + if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); return _cakeMailRestClient.ExecuteArrayRequestAsync(path, parameters, null, cancellationToken); @@ -105,6 +107,7 @@ public Task> AddLocalPartsAsync(string user parameters.Add(new KeyValuePair(string.Format("localpart[{0}]", item.Index), item.LocalPart)); } } + if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); return _cakeMailRestClient.ExecuteArrayRequestAsync(path, parameters, "localparts", cancellationToken); @@ -133,6 +136,7 @@ public Task> RemoveEmailAddressesAsync(string u parameters.Add(new KeyValuePair(string.Format("email[{0}]", item.Index), item.Email)); } } + if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); return _cakeMailRestClient.ExecuteArrayRequestAsync(path, parameters, null, cancellationToken); @@ -161,6 +165,7 @@ public Task> RemoveDomainsAsync(string userKey parameters.Add(new KeyValuePair(string.Format("domain[{0}]", item.Index), item.Domain)); } } + if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); return _cakeMailRestClient.ExecuteArrayRequestAsync(path, parameters, null, cancellationToken); @@ -189,6 +194,7 @@ public Task> RemoveLocalPartsAsync(string u parameters.Add(new KeyValuePair(string.Format("localpart[{0}]", item.Index), item.LocalPart)); } } + if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); return _cakeMailRestClient.ExecuteArrayRequestAsync(path, parameters, "localparts", cancellationToken); diff --git a/Source/CakeMail.RestClient/Resources/Templates.cs b/Source/CakeMail.RestClient/Resources/Templates.cs index caf4831..7075c75 100644 --- a/Source/CakeMail.RestClient/Resources/Templates.cs +++ b/Source/CakeMail.RestClient/Resources/Templates.cs @@ -53,6 +53,7 @@ public Task CreateCategoryAsync(string userKey, IDictionary(string.Format("label[{0}][name]", item.Index), item.Name)); } } + if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); // The data returned when creating a new category is a little bit unusual @@ -184,6 +185,7 @@ public Task UpdateCategoryAsync(string userKey, long categoryId, IDictiona parameters.Add(new KeyValuePair(string.Format("label[{0}]", label.Key), label.Value)); } } + if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); @@ -265,6 +267,7 @@ public Task SetCategoryVisibilityAsync(string userKey, long categoryId, ID parameters.Add(new KeyValuePair(string.Format("client[{0}][visible]", item.Index), item.Visible ? "true" : "false")); } } + if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); @@ -298,6 +301,7 @@ public Task CreateAsync(string userKey, IDictionary labels parameters.Add(new KeyValuePair(string.Format("label[{0}][name]", item.Index), item.Name)); } } + if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); // The data returned when creating a new template is a little bit unusual @@ -431,6 +435,7 @@ public Task UpdateAsync(string userKey, long templateId, IDictionary(string.Format("label[{0}]", label.Key), label.Value)); } } + if (content != null) parameters.Add(new KeyValuePair("content", content)); if (categoryId.HasValue) parameters.Add(new KeyValuePair("category_id", categoryId.Value)); if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); diff --git a/Source/CakeMail.RestClient/Resources/Users.cs b/Source/CakeMail.RestClient/Resources/Users.cs index 418c0cd..83831da 100644 --- a/Source/CakeMail.RestClient/Resources/Users.cs +++ b/Source/CakeMail.RestClient/Resources/Users.cs @@ -199,12 +199,12 @@ public Task UpdateAsync(string userKey, long userId, string email = null, if (mobilePhone != null) parameters.Add(new KeyValuePair("mobile_phone", mobilePhone)); if (language != null) parameters.Add(new KeyValuePair("language", language)); if (timezoneId != null) parameters.Add(new KeyValuePair("timezone_id", timezoneId)); + if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); if (password != null) { parameters.Add(new KeyValuePair("password", password)); parameters.Add(new KeyValuePair("password_confirmation", password)); } - if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); } diff --git a/Source/CakeMail.RestClient/Utilities/ExtensionMethods.cs b/Source/CakeMail.RestClient/Utilities/ExtensionMethods.cs index 2338b8c..d83350c 100644 --- a/Source/CakeMail.RestClient/Utilities/ExtensionMethods.cs +++ b/Source/CakeMail.RestClient/Utilities/ExtensionMethods.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Reflection; using System.Runtime.Serialization; namespace CakeMail.RestClient.Utilities @@ -27,13 +28,14 @@ public static string ToCakeMailString(this DateTime 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; + var fieldInfo = value.GetType().GetField(value.ToString()); + if (fieldInfo == null) return value.ToString(); + + var attributes = fieldInfo.GetCustomAttributes(typeof(EnumMemberAttribute), false).ToArray(); + if (attributes == null || attributes.Length == 0) return value.ToString(); + + var descriptionAttribute = attributes[0] as EnumMemberAttribute; + return (descriptionAttribute == null ? value.ToString() : descriptionAttribute.Value); } /// @@ -44,21 +46,18 @@ public static string GetEnumMemberValue(this Enum value) /// 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 fields = typeof(T).GetFields(); + foreach (var fieldInfo in fields) { - var attribute = Attribute.GetCustomAttribute(field, typeof(EnumMemberAttribute)) as EnumMemberAttribute; - if (attribute != null) + var attributes = fieldInfo.GetCustomAttributes(typeof(EnumMemberAttribute), false).OfType(); + if (attributes.Any(a => a.Value == enumMember)) { - if (attribute.Value == enumMember) return (T)field.GetValue(null); - } - else - { - if (field.Name == enumMember) return (T)field.GetValue(null); + return (T)Enum.Parse(typeof(T), fieldInfo.Name, true); } } - throw new ArgumentException(string.Format("{0} does not have an element with value {1}", typeof(T), enumMember)); + + var message = string.Format("'{0}' is not a valid enumeration of '{1}'", enumMember, typeof(T).Name); + throw new Exception(message); } } } From 9c5a31a71eceeeb82da2c0b98895b2df1a6daa51 Mon Sep 17 00:00:00 2001 From: Jeremie Desautels Date: Sat, 19 Nov 2016 16:38:29 -0600 Subject: [PATCH 08/24] #29 Get rid of RestSharp since it's not compatible with .NET Standard --- .../App.config | 11 - ...akeMail.RestClient.IntegrationTests.csproj | 87 ----- ...CakeMail.RestClient.IntegrationTests.xproj | 19 ++ .../Program.cs | 28 +- .../Properties/AssemblyInfo.cs | 12 - .../WebProxy.cs | 211 ++++++++++++ .../packages.config | 5 - .../project.json | 21 ++ Source/CakeMail.RestClient.sln | 14 +- .../CakeMail.RestClient.xproj | 6 +- .../CakeMail.RestClient/CakeMailRestClient.cs | 312 +++++++++--------- .../Utilities/ExtensionMethods.cs | 19 ++ 12 files changed, 452 insertions(+), 293 deletions(-) delete mode 100644 Source/CakeMail.RestClient.IntegrationTests/App.config delete mode 100644 Source/CakeMail.RestClient.IntegrationTests/CakeMail.RestClient.IntegrationTests.csproj create mode 100644 Source/CakeMail.RestClient.IntegrationTests/CakeMail.RestClient.IntegrationTests.xproj create mode 100644 Source/CakeMail.RestClient.IntegrationTests/WebProxy.cs delete mode 100644 Source/CakeMail.RestClient.IntegrationTests/packages.config create mode 100644 Source/CakeMail.RestClient.IntegrationTests/project.json diff --git a/Source/CakeMail.RestClient.IntegrationTests/App.config b/Source/CakeMail.RestClient.IntegrationTests/App.config deleted file mode 100644 index 789867b..0000000 --- a/Source/CakeMail.RestClient.IntegrationTests/App.config +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/Source/CakeMail.RestClient.IntegrationTests/CakeMail.RestClient.IntegrationTests.csproj b/Source/CakeMail.RestClient.IntegrationTests/CakeMail.RestClient.IntegrationTests.csproj deleted file mode 100644 index 85429ed..0000000 --- a/Source/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/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/Source/CakeMail.RestClient.IntegrationTests/Program.cs b/Source/CakeMail.RestClient.IntegrationTests/Program.cs index f302af4..f842b42 100644 --- a/Source/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 = true; + + // ----------------------------------------------------------------------------- + + + 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/Source/CakeMail.RestClient.IntegrationTests/Properties/AssemblyInfo.cs b/Source/CakeMail.RestClient.IntegrationTests/Properties/AssemblyInfo.cs index 71b2445..c67efce 100644 --- a/Source/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/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/packages.config b/Source/CakeMail.RestClient.IntegrationTests/packages.config deleted file mode 100644 index ef6a3d4..0000000 --- a/Source/CakeMail.RestClient.IntegrationTests/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/Source/CakeMail.RestClient.IntegrationTests/project.json b/Source/CakeMail.RestClient.IntegrationTests/project.json new file mode 100644 index 0000000..7cc0d96 --- /dev/null +++ b/Source/CakeMail.RestClient.IntegrationTests/project.json @@ -0,0 +1,21 @@ +{ + "buildOptions": { + "emitEntryPoint": true + }, + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.1" + }, + "CakeMail.RestClient": { "target": "project" }, + "System.Net.NetworkInformation": "4.3.0", + "System.Net.Security": "4.3.0", + "System.Private.Networking": "4.0.0" + }, + "frameworks": { + "netcoreapp1.0": { + "imports": "dnxcore50" + } + }, + "version": "1.0.0-*" +} diff --git a/Source/CakeMail.RestClient.sln b/Source/CakeMail.RestClient.sln index fb5f73a..513487a 100644 --- a/Source/CakeMail.RestClient.sln +++ b/Source/CakeMail.RestClient.sln @@ -14,22 +14,18 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Source", "Source", "{F7E192 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{9D4FE070-9A1E-4746-BD77-5D81D7FF21FF}" 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 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 Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {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 @@ -38,13 +34,17 @@ Global {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 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {677D93C3-10C8-47AC-B196-60CA28F57A84} = {9D4FE070-9A1E-4746-BD77-5D81D7FF21FF} {B481EE0F-4D2F-40AB-B2B1-7329AFC330DF} = {9D4FE070-9A1E-4746-BD77-5D81D7FF21FF} {DBEFB5D8-8E24-4152-8EFD-EF153FC3A753} = {F7E19221-12B8-4C6E-B87A-167A1E95EBA1} + {B19E7E01-717A-4D0E-B3BC-6D6F26A457A8} = {9D4FE070-9A1E-4746-BD77-5D81D7FF21FF} EndGlobalSection EndGlobal diff --git a/Source/CakeMail.RestClient/CakeMail.RestClient.xproj b/Source/CakeMail.RestClient/CakeMail.RestClient.xproj index 82c63d6..7907143 100644 --- a/Source/CakeMail.RestClient/CakeMail.RestClient.xproj +++ b/Source/CakeMail.RestClient/CakeMail.RestClient.xproj @@ -4,18 +4,16 @@ 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - dbefb5d8-8e24-4152-8efd-ef153fc3a753 - CakeMail.RestClient2 + 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 index 873a3b8..9ae039d 100644 --- a/Source/CakeMail.RestClient/CakeMailRestClient.cs +++ b/Source/CakeMail.RestClient/CakeMailRestClient.cs @@ -2,15 +2,18 @@ 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.Net.Http; +using System.Net.Http.Headers; using System.Reflection; +using System.Text; using System.Threading; using System.Threading.Tasks; +using CakeMail.RestClient.Utilities; namespace CakeMail.RestClient { @@ -19,51 +22,42 @@ namespace CakeMail.RestClient /// public class CakeMailRestClient : ICakeMailRestClient { - #region Fields + #region FIELDS - private static readonly string _version = GetVersion(); - private readonly IRestClient _client; + private const string MEDIA_TYPE = "application/json"; + + private readonly bool _mustDisposeHttpClient; + + private HttpClient _httpClient; + + private enum Methods + { + GET, PUT, POST, PATCH, DELETE + } #endregion - #region Properties + #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; } - } + public string UserAgent { get; private set; } /// /// The timeout /// - public int Timeout - { - get { return _client.Timeout; } - } + public int Timeout { get; private set; } /// /// The URL where all API requests are sent /// - public Uri BaseUrl - { - get { return _client.BaseUrl; } - } + public Uri BaseUrl { get; private set; } /// /// The Campaigns resource @@ -130,21 +124,27 @@ public Uri BaseUrl /// public Triggers Triggers { get; private set; } + public string Version { get; private set; } + #endregion - #region Constructors and Destructors + #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; + public CakeMailRestClient(string apiKey) : this(apiKey, httpClient: (HttpClient)null) { } - InitializeResources(); + /// + /// 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 = null) + : this(apiKey, httpClient: new HttpClient(new HttpClientHandler { Proxy = proxy, UseProxy = proxy != null })) + { + _mustDisposeHttpClient = true; } /// @@ -153,24 +153,67 @@ public CakeMailRestClient(string apiKey, IRestClient restClient) /// 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) + /// 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 = "api.wbsrvc.com", int timeout = 5000, HttpClient httpClient = null) { - this.ApiKey = apiKey; + ApiKey = apiKey; + BaseUrl = new Uri(string.Format("https://{0}", host)); + Timeout = timeout; + + Version = typeof(CakeMailRestClient).GetTypeInfo().Assembly.GetName().Version.ToString(); + UserAgent = string.Format("CakeMail .NET REST Client;{0}", Version); + + _mustDisposeHttpClient = httpClient == null; + _httpClient = httpClient ?? new HttpClient(); + _httpClient.Timeout = TimeSpan.FromMilliseconds(Timeout); + _httpClient.BaseAddress = BaseUrl; + _httpClient.DefaultRequestHeaders.Accept.Clear(); + _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(MEDIA_TYPE)); + _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("apikey", ApiKey); + _httpClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", UserAgent); + + InitializeResources(); + } - _client = new RestSharp.RestClient("https://" + host) + ~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 + + 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); + } + + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + ReleaseManagedResources(); + } + else { - Timeout = timeout, - UserAgent = string.Format("CakeMail .NET REST Client;{0}", _version), - Proxy = webProxy - }; + // 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. + } - InitializeResources(); + ReleaseUnmanagedResources(); } #endregion - #region Internal Methods + #region INTERNAL METHODS internal Task ExecuteCountRequestAsync(string urlPath, IEnumerable> parameters, CancellationToken cancellationToken = default(CancellationToken)) { @@ -187,8 +230,11 @@ internal async Task ExecuteRequestAsync(string urlPath, IEnumerable(); @@ -208,29 +254,20 @@ internal async Task ExecuteRequestAsync(string urlPath, IEnumerable(); } - internal async Task ExecuteRequestAsync(string urlPath, IEnumerable> parameters, CancellationToken cancellationToken = default(CancellationToken)) + internal async Task ExecuteRequestAsync(string endpoint, IEnumerable> parameters, CancellationToken cancellationToken = default(CancellationToken)) { - var request = new RestRequest(urlPath, Method.POST) { RequestFormat = DataFormat.Json }; + var paramsWithValue = parameters.Where(p => p.Value != null).Select(p => string.Concat(Uri.EscapeDataString(p.Key), "=", Uri.EscapeDataString((string)p.Value))); + var paramsWithoutValue = parameters.Where(p => p.Value == null).Select(p => string.Concat(Uri.EscapeDataString(p.Key), "=")); + var allParams = paramsWithValue.Union(paramsWithoutValue).ToArray(); + var content = new StringContent(string.Join("&", paramsWithValue.Union(paramsWithoutValue)), Encoding.UTF8); - 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); + var response = await RequestAsync(Methods.POST, endpoint, content, cancellationToken).ConfigureAwait(false); #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); + var debugRequestMsg = string.Format("Request sent to CakeMail: {0}/{1}", BaseUrl.ToString().TrimEnd('/'), endpoint.TrimStart('/')); + var debugParametersMsg = string.Format("Request parameters: {0}", string.Join("&", parameters.Select(p => string.Concat(p.Key, "=", p.Value)))); + var debugResponseMsg = string.Format("Response received: {0}", await response.Content.ReadAsStringAsync().ConfigureAwait(false)); + Debug.WriteLine("{0}\r\n{1}\r\n{2}\r\n{3}\r\n{0}", new string('=', 25), debugRequestMsg, debugParametersMsg, debugResponseMsg); #endif return response; @@ -238,7 +275,53 @@ internal async Task ExecuteRequestAsync(string urlPath, IEnumerab #endregion - #region Private Methods + #region PRIVATE METHODS + + /// + /// Create a client that connects to the SendGrid Web API + /// + /// HTTP verb, case-insensitive + /// Resource endpoint + /// A StringContent representing the content of the http request + /// An asyncronous task + private async Task RequestAsync(Methods method, string endpoint, StringContent content, CancellationToken cancellationToken = default(CancellationToken)) + { + try + { + var methodAsString = string.Empty; + switch (method) + { + case Methods.GET: methodAsString = "GET"; break; + case Methods.PUT: methodAsString = "PUT"; break; + case Methods.POST: methodAsString = "POST"; break; + case Methods.PATCH: methodAsString = "PATCH"; break; + case Methods.DELETE: methodAsString = "DELETE"; break; + default: + var message = "{\"errors\":[{\"message\":\"Bad method call, supported methods are GET, PUT, POST, PATCH and DELETE\"}]}"; + return new HttpResponseMessage(HttpStatusCode.MethodNotAllowed) + { + Content = new StringContent(message) + }; + } + + var httpRequest = new HttpRequestMessage + { + Method = new HttpMethod(methodAsString), + RequestUri = new Uri(string.Format("{0}{1}{2}", BaseUrl, endpoint.StartsWith("/", StringComparison.Ordinal) ? string.Empty : "/", endpoint)), + Content = content + }; + var response = await _httpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); + return response; + } + catch (Exception ex) + { + var message = string.Format(".NET {0}, raw message: \n\n{1}", (ex is HttpRequestException) ? "HttpRequestException" : "Exception", ex.GetBaseException().Message); + return new HttpResponseMessage(HttpStatusCode.BadRequest) + { + Content = new StringContent(message) + }; + } + } private void InitializeResources() { @@ -257,26 +340,7 @@ private void InitializeResources() 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) + private async Task ParseCakeMailResponseAsync(HttpResponseMessage response) { try { @@ -285,14 +349,15 @@ private JToken ParseCakeMailResponse(IRestResponse response) * "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 responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var cakeResponse = JObject.Parse(responseContent); var status = cakeResponse["status"].ToString(); var data = cakeResponse["data"]; var postData = cakeResponse["post"]; @@ -311,83 +376,18 @@ private JToken ParseCakeMailResponse(IRestResponse response) } } - 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) + private void ReleaseManagedResources() { - 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")) + if (_httpClient != null && _mustDisposeHttpClient) { - 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); + _httpClient.Dispose(); + _httpClient = null; } } - 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) + private void ReleaseUnmanagedResources() { - var responseUri = response.ResponseUri ?? new Uri(string.Format("{0}/{1}", _client.BaseUrl.ToString().TrimEnd('/'), request.Resource.TrimStart('/'))); - return responseUri; + // We do not hold references to unmanaged resources } #endregion diff --git a/Source/CakeMail.RestClient/Utilities/ExtensionMethods.cs b/Source/CakeMail.RestClient/Utilities/ExtensionMethods.cs index d83350c..98c027a 100644 --- a/Source/CakeMail.RestClient/Utilities/ExtensionMethods.cs +++ b/Source/CakeMail.RestClient/Utilities/ExtensionMethods.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Net.Http; using System.Reflection; using System.Runtime.Serialization; @@ -59,5 +60,23 @@ public static string GetEnumMemberValue(this Enum value) var message = string.Format("'{0}' is not a valid enumeration of '{1}'", enumMember, typeof(T).Name); throw new Exception(message); } + + public static void EnsureSuccess(this HttpResponseMessage response) + { + if (response.IsSuccessStatusCode) return; + + var content = string.Empty; + if (response.Content != null) + { + content = response.Content.ReadAsStringAsync().Result; + response.Content.Dispose(); + } + else + { + content = string.Format("StatusCode: {0}", response.StatusCode); + } + + throw new Exception(content); + } } } From cd8edb7db83d96fe39daa293b3e0b95c80742e83 Mon Sep 17 00:00:00 2001 From: Jeremie Desautels Date: Sat, 19 Nov 2016 16:56:37 -0600 Subject: [PATCH 09/24] Standardize the AssemblyInfo --- .../Properties/AssemblyInfo.cs | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/Source/CakeMail.RestClient/Properties/AssemblyInfo.cs b/Source/CakeMail.RestClient/Properties/AssemblyInfo.cs index 146a640..8148e57 100644 --- a/Source/CakeMail.RestClient/Properties/AssemblyInfo.cs +++ b/Source/CakeMail.RestClient/Properties/AssemblyInfo.cs @@ -1,27 +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: 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")] +// 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")] + From 5d6453a8767c4448968630fafb224cf16fc0ed91 Mon Sep 17 00:00:00 2001 From: Jeremie Desautels Date: Sat, 19 Nov 2016 16:56:57 -0600 Subject: [PATCH 10/24] Set version number to 6.0.0 --- Source/CakeMail.RestClient/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/CakeMail.RestClient/project.json b/Source/CakeMail.RestClient/project.json index 051e0fa..d259c91 100644 --- a/Source/CakeMail.RestClient/project.json +++ b/Source/CakeMail.RestClient/project.json @@ -102,5 +102,5 @@ } } }, - "version": "1.0.0-*" + "version": "6.0.0-*" } From d52df7c32daa13a7069eb4999ea5fa28b93b46d3 Mon Sep 17 00:00:00 2001 From: Jeremie Desautels Date: Sat, 19 Nov 2016 16:57:35 -0600 Subject: [PATCH 11/24] Fix an issue with the apikey being in the wrong HTTP header --- .../CakeMail.RestClient/CakeMailRestClient.cs | 35 ++++++++----------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/Source/CakeMail.RestClient/CakeMailRestClient.cs b/Source/CakeMail.RestClient/CakeMailRestClient.cs index 9ae039d..7af0ba3 100644 --- a/Source/CakeMail.RestClient/CakeMailRestClient.cs +++ b/Source/CakeMail.RestClient/CakeMailRestClient.cs @@ -163,16 +163,28 @@ public CakeMailRestClient(string apiKey, string host = "api.wbsrvc.com", int tim Version = typeof(CakeMailRestClient).GetTypeInfo().Assembly.GetName().Version.ToString(); UserAgent = string.Format("CakeMail .NET REST Client;{0}", Version); + Campaigns = new Campaigns(this); + Clients = new Clients(this); + Countries = new Countries(this); + Permissions = new Permissions(this); + Lists = new Lists(this); + Timezones = new Timezones(this); + Mailings = new Mailings(this); + Relays = new Relays(this); + Segments = new Segments(this); + Users = new Users(this); + SuppressionLists = new SuppressionLists(this); + Templates = new Templates(this); + Triggers = new Triggers(this); + _mustDisposeHttpClient = httpClient == null; _httpClient = httpClient ?? new HttpClient(); _httpClient.Timeout = TimeSpan.FromMilliseconds(Timeout); _httpClient.BaseAddress = BaseUrl; _httpClient.DefaultRequestHeaders.Accept.Clear(); _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(MEDIA_TYPE)); - _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("apikey", ApiKey); + _httpClient.DefaultRequestHeaders.Add("apikey", ApiKey); _httpClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", UserAgent); - - InitializeResources(); } ~CakeMailRestClient() @@ -323,23 +335,6 @@ private async Task RequestAsync(Methods method, string endp } } - 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 async Task ParseCakeMailResponseAsync(HttpResponseMessage response) { try From 8b65c37a5807a7eeacf43c084314c5500011265e Mon Sep 17 00:00:00 2001 From: Jeremie Desautels Date: Sat, 19 Nov 2016 18:34:29 -0600 Subject: [PATCH 12/24] Make sure Fiddler is turned off by default --- Source/CakeMail.RestClient.IntegrationTests/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/CakeMail.RestClient.IntegrationTests/Program.cs b/Source/CakeMail.RestClient.IntegrationTests/Program.cs index f842b42..821142b 100644 --- a/Source/CakeMail.RestClient.IntegrationTests/Program.cs +++ b/Source/CakeMail.RestClient.IntegrationTests/Program.cs @@ -37,7 +37,7 @@ private static void ExecuteAllMethods() // ----------------------------------------------------------------------------- // Do you want to proxy requests through Fiddler (useful for debugging)? - var useFiddler = true; + var useFiddler = false; // ----------------------------------------------------------------------------- From 8f323a86227af8edbd98931a4dd728c5835c212f Mon Sep 17 00:00:00 2001 From: Jeremie Desautels Date: Sat, 19 Nov 2016 18:37:59 -0600 Subject: [PATCH 13/24] Misc fixes and improvements. Fix an issue that caused request Url to contain '//'. Improve integration testing to try to avoid duplicate admin email addresses when creating a new client Fix an issue when attempting to post zero parameters Make sure we post the appropriate mediaType --- .../Clients.cs | 9 +++++---- .../CakeMail.RestClient/CakeMailRestClient.cs | 20 ++++++++++--------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Source/CakeMail.RestClient.IntegrationTests/Clients.cs b/Source/CakeMail.RestClient.IntegrationTests/Clients.cs index a5c5250..8a3973a 100644 --- a/Source/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}@integrationtesting.com", clientsCount); + 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/Source/CakeMail.RestClient/CakeMailRestClient.cs b/Source/CakeMail.RestClient/CakeMailRestClient.cs index 7af0ba3..5892b17 100644 --- a/Source/CakeMail.RestClient/CakeMailRestClient.cs +++ b/Source/CakeMail.RestClient/CakeMailRestClient.cs @@ -24,8 +24,6 @@ public class CakeMailRestClient : ICakeMailRestClient { #region FIELDS - private const string MEDIA_TYPE = "application/json"; - private readonly bool _mustDisposeHttpClient; private HttpClient _httpClient; @@ -182,7 +180,7 @@ public CakeMailRestClient(string apiKey, string host = "api.wbsrvc.com", int tim _httpClient.Timeout = TimeSpan.FromMilliseconds(Timeout); _httpClient.BaseAddress = BaseUrl; _httpClient.DefaultRequestHeaders.Accept.Clear(); - _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(MEDIA_TYPE)); + _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); _httpClient.DefaultRequestHeaders.Add("apikey", ApiKey); _httpClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", UserAgent); } @@ -268,16 +266,20 @@ internal async Task ExecuteRequestAsync(string urlPath, IEnumerable ExecuteRequestAsync(string endpoint, IEnumerable> parameters, CancellationToken cancellationToken = default(CancellationToken)) { - var paramsWithValue = parameters.Where(p => p.Value != null).Select(p => string.Concat(Uri.EscapeDataString(p.Key), "=", Uri.EscapeDataString((string)p.Value))); - var paramsWithoutValue = parameters.Where(p => p.Value == null).Select(p => string.Concat(Uri.EscapeDataString(p.Key), "=")); - var allParams = paramsWithValue.Union(paramsWithoutValue).ToArray(); - var content = new StringContent(string.Join("&", paramsWithValue.Union(paramsWithoutValue)), Encoding.UTF8); + var content = (StringContent)null; + if (parameters != null) + { + var paramsWithValue = parameters.Where(p => p.Value != null).Select(p => string.Concat(Uri.EscapeDataString(p.Key), "=", Uri.EscapeDataString(p.Value.ToString()))); + var paramsWithoutValue = parameters.Where(p => p.Value == null).Select(p => string.Concat(Uri.EscapeDataString(p.Key), "=")); + var allParams = paramsWithValue.Union(paramsWithoutValue).ToArray(); + content = new StringContent(string.Join("&", paramsWithValue.Union(paramsWithoutValue)), Encoding.UTF8, "application/x-www-form-urlencoded"); + } var response = await RequestAsync(Methods.POST, endpoint, content, cancellationToken).ConfigureAwait(false); #if DEBUG var debugRequestMsg = string.Format("Request sent to CakeMail: {0}/{1}", BaseUrl.ToString().TrimEnd('/'), endpoint.TrimStart('/')); - var debugParametersMsg = string.Format("Request parameters: {0}", string.Join("&", parameters.Select(p => string.Concat(p.Key, "=", p.Value)))); + var debugParametersMsg = string.Format("Request parameters: {0}", parameters == null ? "[NULL]" : string.Join("&", parameters.Select(p => string.Concat(p.Key, "=", p.Value)))); var debugResponseMsg = string.Format("Response received: {0}", await response.Content.ReadAsStringAsync().ConfigureAwait(false)); Debug.WriteLine("{0}\r\n{1}\r\n{2}\r\n{3}\r\n{0}", new string('=', 25), debugRequestMsg, debugParametersMsg, debugResponseMsg); #endif @@ -319,7 +321,7 @@ private async Task RequestAsync(Methods method, string endp var httpRequest = new HttpRequestMessage { Method = new HttpMethod(methodAsString), - RequestUri = new Uri(string.Format("{0}{1}{2}", BaseUrl, endpoint.StartsWith("/", StringComparison.Ordinal) ? string.Empty : "/", endpoint)), + RequestUri = new Uri(BaseUrl, endpoint), Content = content }; var response = await _httpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); From 5839103b60e4c34ece4349a86bb08365476439ee Mon Sep 17 00:00:00 2001 From: Jeremie Desautels Date: Sat, 19 Nov 2016 18:43:12 -0600 Subject: [PATCH 14/24] #30 Decorate the Client.LastActivityOn field with the appropriate date parser --- Source/CakeMail.RestClient/Models/Client.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/CakeMail.RestClient/Models/Client.cs b/Source/CakeMail.RestClient/Models/Client.cs index 7812b8b..8c9cdfd 100644 --- a/Source/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 +} From 726a4101d6e0fcf2a472e1dd63b930fb2928f709 Mon Sep 17 00:00:00 2001 From: Jeremie Desautels Date: Wed, 8 Feb 2017 09:25:06 -0600 Subject: [PATCH 15/24] Switch unit test project to .net core --- .../project.json | 10 +- .../CakeMail.RestClient.UnitTests.csproj | 134 ------------------ .../CakeMail.RestClient.UnitTests.xproj | 21 +++ .../packages.config | 8 -- .../project.json | 23 +++ Source/CakeMail.RestClient.sln | 14 +- 6 files changed, 56 insertions(+), 154 deletions(-) delete mode 100644 Source/CakeMail.RestClient.UnitTests/CakeMail.RestClient.UnitTests.csproj create mode 100644 Source/CakeMail.RestClient.UnitTests/CakeMail.RestClient.UnitTests.xproj delete mode 100644 Source/CakeMail.RestClient.UnitTests/packages.config create mode 100644 Source/CakeMail.RestClient.UnitTests/project.json diff --git a/Source/CakeMail.RestClient.IntegrationTests/project.json b/Source/CakeMail.RestClient.IntegrationTests/project.json index 7cc0d96..596ec07 100644 --- a/Source/CakeMail.RestClient.IntegrationTests/project.json +++ b/Source/CakeMail.RestClient.IntegrationTests/project.json @@ -1,13 +1,13 @@ -{ +{ "buildOptions": { "emitEntryPoint": true }, "dependencies": { - "Microsoft.NETCore.App": { - "type": "platform", - "version": "1.0.1" - }, "CakeMail.RestClient": { "target": "project" }, + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.1.0" + }, "System.Net.NetworkInformation": "4.3.0", "System.Net.Security": "4.3.0", "System.Private.Networking": "4.0.0" diff --git a/Source/CakeMail.RestClient.UnitTests/CakeMail.RestClient.UnitTests.csproj b/Source/CakeMail.RestClient.UnitTests/CakeMail.RestClient.UnitTests.csproj deleted file mode 100644 index 05f8498..0000000 --- a/Source/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/Source/CakeMail.RestClient.UnitTests/CakeMail.RestClient.UnitTests.xproj b/Source/CakeMail.RestClient.UnitTests/CakeMail.RestClient.UnitTests.xproj new file mode 100644 index 0000000..73828fd --- /dev/null +++ b/Source/CakeMail.RestClient.UnitTests/CakeMail.RestClient.UnitTests.xproj @@ -0,0 +1,21 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + 964d6bc3-6daa-4878-bbae-839ae9942baf + CakeMail.RestClient.UnitTests2 + .\obj + .\bin\ + v4.5.2 + + + + 2.0 + + + diff --git a/Source/CakeMail.RestClient.UnitTests/packages.config b/Source/CakeMail.RestClient.UnitTests/packages.config deleted file mode 100644 index 0c76fd1..0000000 --- a/Source/CakeMail.RestClient.UnitTests/packages.config +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/Source/CakeMail.RestClient.UnitTests/project.json b/Source/CakeMail.RestClient.UnitTests/project.json new file mode 100644 index 0000000..b3b415d --- /dev/null +++ b/Source/CakeMail.RestClient.UnitTests/project.json @@ -0,0 +1,23 @@ +{ + "version": "1.0.0-*", + "testRunner": "xunit", + "dependencies": { + "CakeMail.RestClient": { "target": "project" }, + "dotnet-test-xunit": "2.2.0-preview2-build1029", + "Moq": "4.6.38-alpha", + "RichardSzalay.MockHttp": "1.4.1", + "Shouldly": "2.8.2", + "xunit": "2.2.0-beta4-build3444" + }, + "frameworks": { + "netcoreapp1.0": { + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.1.0" + } + + } + } + } +} diff --git a/Source/CakeMail.RestClient.sln b/Source/CakeMail.RestClient.sln index 513487a..33909f8 100644 --- a/Source/CakeMail.RestClient.sln +++ b/Source/CakeMail.RestClient.sln @@ -14,22 +14,18 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Source", "Source", "{F7E192 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{9D4FE070-9A1E-4746-BD77-5D81D7FF21FF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CakeMail.RestClient.UnitTests", "CakeMail.RestClient.UnitTests\CakeMail.RestClient.UnitTests.csproj", "{B481EE0F-4D2F-40AB-B2B1-7329AFC330DF}" -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 - {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 {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 @@ -38,13 +34,17 @@ Global {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 - {B481EE0F-4D2F-40AB-B2B1-7329AFC330DF} = {9D4FE070-9A1E-4746-BD77-5D81D7FF21FF} {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 From 2e744ef5db082e20f680cba63051843e22c078f7 Mon Sep 17 00:00:00 2001 From: Jeremie Desautels Date: Wed, 8 Feb 2017 09:55:59 -0600 Subject: [PATCH 16/24] Improve project.json: only net452 and netstandard1.3 --- Source/CakeMail.RestClient/project.json | 64 ++----------------------- 1 file changed, 4 insertions(+), 60 deletions(-) diff --git a/Source/CakeMail.RestClient/project.json b/Source/CakeMail.RestClient/project.json index d259c91..ff6b1e5 100644 --- a/Source/CakeMail.RestClient/project.json +++ b/Source/CakeMail.RestClient/project.json @@ -18,88 +18,32 @@ } }, "dependencies": { + "Newtonsoft.Json": "9.0.1", "StyleCop.Analyzers": { "version": "1.0.0", "type": "build" } }, "frameworks": { - "netstandard1.6": { - "buildOptions": { - "define": [ "NETSTANDARD", "NETSTANDARD16" ] - }, - "imports": "dnxcore50", - "dependencies": { - "NETStandard.Library": "1.6.1", - "Newtonsoft.Json": "9.0.1", - "System.ComponentModel.Primitives": "4.3.0", - "System.Reflection.TypeExtensions": "4.3.0", - "System.Runtime.Serialization.Primitives": "4.3.0" - } - }, "netstandard1.3": { "buildOptions": { - "define": [ "NETSTANDARD", "NETSTANDARD13" ] + "define": [ "NETSTANDARD" ] }, "imports": "dnxcore50", "dependencies": { - "NETStandard.Library": "1.6.1", - "Newtonsoft.Json": "9.0.1", - "System.ComponentModel.Primitives": "4.3.0", - "System.Reflection.TypeExtensions": "4.1.0", - "System.Runtime.Serialization.Primitives": "4.3.0" + "NETStandard.Library": "1.6.1" } }, "net452": { "buildOptions": { - "define": [ "NET452" ] + "define": [ "NETFULL" ] }, "dependencies": { - "Newtonsoft.Json": "9.0.1", "System.Net.Http": "4.0.0" }, "frameworkAssemblies": { "System.Runtime.Serialization": "4.0.0" } - }, - "net46": { - "buildOptions": { - "define": [ "NET46" ] - }, - "dependencies": { - "Newtonsoft.Json": "9.0.1", - "System.Net.Http": "4.0.0", - "System.Reflection.TypeExtensions": "4.3.0" - }, - "frameworkAssemblies": { - "System.Runtime.Serialization": "4.0.0" - } - }, - "net461": { - "buildOptions": { - "define": [ "NET461" ] - }, - "dependencies": { - "Newtonsoft.Json": "9.0.1", - "System.Net.Http": "4.0.0", - "System.Reflection.TypeExtensions": "4.3.0" - }, - "frameworkAssemblies": { - "System.Runtime.Serialization": "4.0.0" - } - }, - "net462": { - "buildOptions": { - "define": [ "NET462" ] - }, - "dependencies": { - "Newtonsoft.Json": "9.0.1", - "System.Net.Http": "4.0.0", - "System.Reflection.TypeExtensions": "4.3.0" - }, - "frameworkAssemblies": { - "System.Runtime.Serialization": "4.0.0" - } } }, "version": "6.0.0-*" From 16a45375d93f8b58a75c57f490094972304a867f Mon Sep 17 00:00:00 2001 From: Jeremie Desautels Date: Wed, 8 Feb 2017 11:18:05 -0600 Subject: [PATCH 17/24] Ensure URIs a re properly formed. Add a few missing XML comments --- .../CakeMail.RestClient/CakeMailRestClient.cs | 28 +++++++++++++++---- .../Resources/Campaigns.cs | 4 +++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Source/CakeMail.RestClient/CakeMailRestClient.cs b/Source/CakeMail.RestClient/CakeMailRestClient.cs index 5892b17..32f9a0f 100644 --- a/Source/CakeMail.RestClient/CakeMailRestClient.cs +++ b/Source/CakeMail.RestClient/CakeMailRestClient.cs @@ -122,6 +122,12 @@ private enum Methods /// public Triggers Triggers { get; private set; } + /// + /// Gets the Version. + /// + /// + /// The version. + /// public string Version { get; private set; } #endregion @@ -139,7 +145,7 @@ private enum Methods /// /// The API Key received from CakeMail /// Allows you to specify a proxy - public CakeMailRestClient(string apiKey, IWebProxy proxy = null) + public CakeMailRestClient(string apiKey, IWebProxy proxy) : this(apiKey, httpClient: new HttpClient(new HttpClientHandler { Proxy = proxy, UseProxy = proxy != null })) { _mustDisposeHttpClient = true; @@ -155,11 +161,11 @@ public CakeMailRestClient(string apiKey, IWebProxy proxy = null) public CakeMailRestClient(string apiKey, string host = "api.wbsrvc.com", int timeout = 5000, HttpClient httpClient = null) { ApiKey = apiKey; - BaseUrl = new Uri(string.Format("https://{0}", host)); + BaseUrl = new Uri($"https://{host.TrimEnd('/')}/"); Timeout = timeout; Version = typeof(CakeMailRestClient).GetTypeInfo().Assembly.GetName().Version.ToString(); - UserAgent = string.Format("CakeMail .NET REST Client;{0}", Version); + UserAgent = $"CakeMail.NET REST Client/{Version} (+https://github.com/Jericho/CakeMail.RestClient)"; Campaigns = new Campaigns(this); Clients = new Clients(this); @@ -185,6 +191,9 @@ public CakeMailRestClient(string apiKey, string host = "api.wbsrvc.com", int tim _httpClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", UserAgent); } + /// + /// Finalizes an instance of the class. + /// ~CakeMailRestClient() { // The object went out of scope and finalized is called. @@ -197,6 +206,9 @@ public CakeMailRestClient(string apiKey, string host = "api.wbsrvc.com", int tim #region PUBLIC METHODS + /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// public void Dispose() { // Call 'Dispose' to release resources @@ -206,6 +218,10 @@ public void Dispose() 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) @@ -246,7 +262,7 @@ internal async Task ExecuteRequestAsync(string urlPath, IEnumerable(); else if (data is JValue) return (data as JValue).ToObject(); @@ -272,7 +288,7 @@ internal async Task ExecuteRequestAsync(string endpoint, IE var paramsWithValue = parameters.Where(p => p.Value != null).Select(p => string.Concat(Uri.EscapeDataString(p.Key), "=", Uri.EscapeDataString(p.Value.ToString()))); var paramsWithoutValue = parameters.Where(p => p.Value == null).Select(p => string.Concat(Uri.EscapeDataString(p.Key), "=")); var allParams = paramsWithValue.Union(paramsWithoutValue).ToArray(); - content = new StringContent(string.Join("&", paramsWithValue.Union(paramsWithoutValue)), Encoding.UTF8, "application/x-www-form-urlencoded"); + content = new StringContent(string.Join("&", allParams), Encoding.UTF8, "application/x-www-form-urlencoded"); } var response = await RequestAsync(Methods.POST, endpoint, content, cancellationToken).ConfigureAwait(false); @@ -321,7 +337,7 @@ private async Task RequestAsync(Methods method, string endp var httpRequest = new HttpRequestMessage { Method = new HttpMethod(methodAsString), - RequestUri = new Uri(BaseUrl, endpoint), + RequestUri = new Uri(BaseUrl, endpoint.TrimStart('/')), Content = content }; var response = await _httpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); diff --git a/Source/CakeMail.RestClient/Resources/Campaigns.cs b/Source/CakeMail.RestClient/Resources/Campaigns.cs index 03e4987..bbe623f 100644 --- a/Source/CakeMail.RestClient/Resources/Campaigns.cs +++ b/Source/CakeMail.RestClient/Resources/Campaigns.cs @@ -16,6 +16,10 @@ public class Campaigns #region Constructor + /// + /// Initializes a new instance of the class. + /// + /// The HTTP client public Campaigns(CakeMailRestClient cakeMailRestClient) { _cakeMailRestClient = cakeMailRestClient; From 2cc5b61397edb0a68c2e149c00091942a7952e32 Mon Sep 17 00:00:00 2001 From: Jeremie Desautels Date: Thu, 9 Feb 2017 13:34:00 -0600 Subject: [PATCH 18/24] Misc cleanup --- .../CakeMail.RestClient.UnitTests.xproj | 9 ++- .../MockRestClient.cs | 75 ------------------- .../Utilities/CakeMailArrayConverter.cs | 70 ----------------- .../CakeMail.RestClient/CakeMailRestClient.cs | 4 +- .../ICakeMailRestClient.cs | 5 +- .../Resources/Campaigns.cs | 14 ++-- .../Resources/Countries.cs | 4 +- .../Resources/Timezones.cs | 2 +- .../Utilities/ExtensionMethods.cs | 2 +- Source/CakeMail.RestClient/project.json | 3 +- nuspec/CakeMail.RestClient.nuspec | 33 +------- 11 files changed, 25 insertions(+), 196 deletions(-) delete mode 100644 Source/CakeMail.RestClient.UnitTests/MockRestClient.cs delete mode 100644 Source/CakeMail.RestClient.UnitTests/Utilities/CakeMailArrayConverter.cs diff --git a/Source/CakeMail.RestClient.UnitTests/CakeMail.RestClient.UnitTests.xproj b/Source/CakeMail.RestClient.UnitTests/CakeMail.RestClient.UnitTests.xproj index 73828fd..a8c6a69 100644 --- a/Source/CakeMail.RestClient.UnitTests/CakeMail.RestClient.UnitTests.xproj +++ b/Source/CakeMail.RestClient.UnitTests/CakeMail.RestClient.UnitTests.xproj @@ -4,18 +4,19 @@ 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - 964d6bc3-6daa-4878-bbae-839ae9942baf - CakeMail.RestClient.UnitTests2 + CakeMail.RestClient.UnitTests .\obj .\bin\ v4.5.2 - 2.0 + + + - + \ No newline at end of file diff --git a/Source/CakeMail.RestClient.UnitTests/MockRestClient.cs b/Source/CakeMail.RestClient.UnitTests/MockRestClient.cs deleted file mode 100644 index e00378f..0000000 --- a/Source/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/Source/CakeMail.RestClient.UnitTests/Utilities/CakeMailArrayConverter.cs b/Source/CakeMail.RestClient.UnitTests/Utilities/CakeMailArrayConverter.cs deleted file mode 100644 index d5bdcd6..0000000 --- a/Source/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/Source/CakeMail.RestClient/CakeMailRestClient.cs b/Source/CakeMail.RestClient/CakeMailRestClient.cs index 32f9a0f..d28d3bd 100644 --- a/Source/CakeMail.RestClient/CakeMailRestClient.cs +++ b/Source/CakeMail.RestClient/CakeMailRestClient.cs @@ -165,7 +165,7 @@ public CakeMailRestClient(string apiKey, string host = "api.wbsrvc.com", int tim Timeout = timeout; Version = typeof(CakeMailRestClient).GetTypeInfo().Assembly.GetName().Version.ToString(); - UserAgent = $"CakeMail.NET REST Client/{Version} (+https://github.com/Jericho/CakeMail.RestClient)"; + UserAgent = $"CakeMail .NET REST Client/{Version} (+https://github.com/Jericho/CakeMail.RestClient)"; Campaigns = new Campaigns(this); Clients = new Clients(this); @@ -296,7 +296,7 @@ internal async Task ExecuteRequestAsync(string endpoint, IE #if DEBUG var debugRequestMsg = string.Format("Request sent to CakeMail: {0}/{1}", BaseUrl.ToString().TrimEnd('/'), endpoint.TrimStart('/')); var debugParametersMsg = string.Format("Request parameters: {0}", parameters == null ? "[NULL]" : string.Join("&", parameters.Select(p => string.Concat(p.Key, "=", p.Value)))); - var debugResponseMsg = string.Format("Response received: {0}", await response.Content.ReadAsStringAsync().ConfigureAwait(false)); + var debugResponseMsg = string.Format("Response received: {0}", response.Content == null ? "[NULL]" : await response.Content.ReadAsStringAsync().ConfigureAwait(false)); Debug.WriteLine("{0}\r\n{1}\r\n{2}\r\n{3}\r\n{0}", new string('=', 25), debugRequestMsg, debugParametersMsg, debugResponseMsg); #endif diff --git a/Source/CakeMail.RestClient/ICakeMailRestClient.cs b/Source/CakeMail.RestClient/ICakeMailRestClient.cs index a261216..0b47de5 100644 --- a/Source/CakeMail.RestClient/ICakeMailRestClient.cs +++ b/Source/CakeMail.RestClient/ICakeMailRestClient.cs @@ -1,8 +1,5 @@ -using CakeMail.RestClient.Models; -using CakeMail.RestClient.Resources; +using CakeMail.RestClient.Resources; using System; -using System.Collections.Generic; -using System.Net; namespace CakeMail.RestClient { diff --git a/Source/CakeMail.RestClient/Resources/Campaigns.cs b/Source/CakeMail.RestClient/Resources/Campaigns.cs index bbe623f..dd473f4 100644 --- a/Source/CakeMail.RestClient/Resources/Campaigns.cs +++ b/Source/CakeMail.RestClient/Resources/Campaigns.cs @@ -19,7 +19,7 @@ public class Campaigns /// /// Initializes a new instance of the class. /// - /// The HTTP client + /// The HTTP client public Campaigns(CakeMailRestClient cakeMailRestClient) { _cakeMailRestClient = cakeMailRestClient; @@ -39,7 +39,7 @@ 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/"; + string path = "/Campaign/Create"; var parameters = new List> { @@ -61,7 +61,7 @@ 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/"; + string path = "/Campaign/Delete"; var parameters = new List> { @@ -83,7 +83,7 @@ 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 path = "/Campaign/GetInfo"; var parameters = new List> { @@ -110,7 +110,7 @@ public Task GetAsync(string userKey, long campaignId, long? clientId = /// 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)) { - var path = "/Campaign/GetList/"; + var path = "/Campaign/GetList"; var parameters = new List> { @@ -139,7 +139,7 @@ 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 path = "/Campaign/GetList"; var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -163,7 +163,7 @@ 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/"; + string path = "/Campaign/SetInfo"; var parameters = new List> { diff --git a/Source/CakeMail.RestClient/Resources/Countries.cs b/Source/CakeMail.RestClient/Resources/Countries.cs index 97b54b1..b0ac82c 100644 --- a/Source/CakeMail.RestClient/Resources/Countries.cs +++ b/Source/CakeMail.RestClient/Resources/Countries.cs @@ -31,7 +31,7 @@ public Countries(CakeMailRestClient cakeMailRestClient) /// An enumeration of countries public Task> GetListAsync(CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/Country/GetList/"; + var path = "/Country/GetList"; return _cakeMailRestClient.ExecuteArrayRequestAsync(path, null, "countries", cancellationToken); } @@ -44,7 +44,7 @@ public Task> GetListAsync(CancellationToken cancellationTok /// An enumeration of privinces public Task> GetProvincesAsync(string countryId, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/Country/GetProvinces/"; + var path = "/Country/GetProvinces"; var parameters = new List> { diff --git a/Source/CakeMail.RestClient/Resources/Timezones.cs b/Source/CakeMail.RestClient/Resources/Timezones.cs index 207db23..f122c5f 100644 --- a/Source/CakeMail.RestClient/Resources/Timezones.cs +++ b/Source/CakeMail.RestClient/Resources/Timezones.cs @@ -30,7 +30,7 @@ public Timezones(CakeMailRestClient cakeMailRestClient) /// An enumeration of all timezones. public Task> GetAllAsync(CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/Client/GetTimezones/"; + var path = "Client/GetTimezones"; return _cakeMailRestClient.ExecuteArrayRequestAsync(path, null, "timezones", cancellationToken); } diff --git a/Source/CakeMail.RestClient/Utilities/ExtensionMethods.cs b/Source/CakeMail.RestClient/Utilities/ExtensionMethods.cs index 98c027a..ae99924 100644 --- a/Source/CakeMail.RestClient/Utilities/ExtensionMethods.cs +++ b/Source/CakeMail.RestClient/Utilities/ExtensionMethods.cs @@ -51,7 +51,7 @@ public static string GetEnumMemberValue(this Enum value) foreach (var fieldInfo in fields) { var attributes = fieldInfo.GetCustomAttributes(typeof(EnumMemberAttribute), false).OfType(); - if (attributes.Any(a => a.Value == enumMember)) + if (attributes.Any(a => a.Value == enumMember) || fieldInfo.Name == enumMember) { return (T)Enum.Parse(typeof(T), fieldInfo.Name, true); } diff --git a/Source/CakeMail.RestClient/project.json b/Source/CakeMail.RestClient/project.json index ff6b1e5..0b0ca33 100644 --- a/Source/CakeMail.RestClient/project.json +++ b/Source/CakeMail.RestClient/project.json @@ -31,7 +31,8 @@ }, "imports": "dnxcore50", "dependencies": { - "NETStandard.Library": "1.6.1" + "NETStandard.Library": "1.6.1", + "System.Reflection.TypeExtensions": "4.1.0" } }, "net452": { diff --git a/nuspec/CakeMail.RestClient.nuspec b/nuspec/CakeMail.RestClient.nuspec index ecdf4eb..2a4171c 100644 --- a/nuspec/CakeMail.RestClient.nuspec +++ b/nuspec/CakeMail.RestClient.nuspec @@ -3,7 +3,7 @@ CakeMail.RestClient 0.0.0 - $title$ + CakeMail.RestClient Jeremie Desautels Jeremie Desautels Strongly typed library for CakeMail's API @@ -18,30 +18,11 @@ - - - - - - - - - - - - - + - - - - - - - @@ -49,15 +30,9 @@ - - - - - - + - - + From 88b5589c4cf3c554915d666547a0aa9e822f1d33 Mon Sep 17 00:00:00 2001 From: Jeremie Desautels Date: Thu, 9 Feb 2017 13:36:48 -0600 Subject: [PATCH 19/24] Convert unit tests to xUnit --- .../CakeMailRestClientTests.cs | 326 ++-- .../Campaigns.cs | 277 ++- .../CakeMail.RestClient.UnitTests/Clients.cs | 688 +++----- .../Countries.cs | 30 +- .../Exceptions/CakeMailException.cs | 9 +- .../Exceptions/CakeMailPostException.cs | 7 +- .../Exceptions/HttpException.cs | 7 +- Source/CakeMail.RestClient.UnitTests/Lists.cs | 1499 +++++------------ .../CakeMail.RestClient.UnitTests/Mailings.cs | 1470 ++++++---------- .../Permissions.cs | 58 +- .../CakeMail.RestClient.UnitTests/Relays.cs | 277 +-- .../CakeMail.RestClient.UnitTests/Segments.cs | 253 +-- .../SuppressionLists.cs | 444 ++--- .../Templates.cs | 658 +++----- .../Timezones.cs | 18 +- .../CakeMail.RestClient.UnitTests/Triggers.cs | 1160 ++++--------- Source/CakeMail.RestClient.UnitTests/Users.cs | 450 ++--- .../Utilities/CakeMailDateTimeConverter.cs | 30 +- .../CakeMailIntegerBooleanConverter.cs | 28 +- .../Utilities/ExtensionMethods.cs | 33 +- Source/CakeMail.RestClient.UnitTests/Utils.cs | 14 + .../project.json | 31 +- 22 files changed, 2588 insertions(+), 5179 deletions(-) create mode 100644 Source/CakeMail.RestClient.UnitTests/Utils.cs diff --git a/Source/CakeMail.RestClient.UnitTests/CakeMailRestClientTests.cs b/Source/CakeMail.RestClient.UnitTests/CakeMailRestClientTests.cs index 1cfd74d..8cefacb 100644 --- a/Source/CakeMail.RestClient.UnitTests/CakeMailRestClientTests.cs +++ b/Source/CakeMail.RestClient.UnitTests/CakeMailRestClientTests.cs @@ -1,271 +1,289 @@ using CakeMail.RestClient.Exceptions; -using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; -using RestSharp; +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 { - [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() + [Fact] + public void Version_is_not_empty() { // Arrange - var mockHost = "myhost"; - var mockProxyHost = "localhost"; - var mockProxyPort = 8888; - var mockTimeout = 777; + var client = new CakeMailRestClient(API_KEY); // 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; + var result = client.Version; // 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))); + 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; + var timeout = client.Timeout; + + // 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")); + timeout.ShouldBe(5000); } - [TestMethod] - public void RestClient_constructor_with_IRestClient() + [Fact] + public void RestClient_constructor_with_IWebProxy() { // 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 mockProxy = new Mock(MockBehavior.Strict); + + // Act + var client = new CakeMailRestClient(API_KEY, mockProxy.Object); + var baseUrl = client.BaseUrl; + var timeout = client.Timeout; + + // Assert + baseUrl.ShouldBe(new Uri("https://api.wbsrvc.com")); + timeout.ShouldBe(5000); + } + + [Fact] + public void RestClient_constructor_with_HttpClient() + { + // Arrange + var mockHost = "my.apiserver.com"; 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); + var mockHttp = new MockHttpMessageHandler(); + var httpClient = new HttpClient(mockHttp); // 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; + var client = new CakeMailRestClient(API_KEY, mockHost, mockTimeout, httpClient); + var baseUrl = client.BaseUrl; + var timeout = client.Timeout; // Assert - userAgent.ShouldBe(mockUserAgent); - baseUrl.ShouldBe(mockBaseUrl); + mockHttp.VerifyNoOutstandingExpectation(); + mockHttp.VerifyNoOutstandingRequest(); + baseUrl.ShouldBe(new Uri($"https://{mockHost}")); timeout.ShouldBe(mockTimeout); - ((WebProxy)proxy).Address.ShouldBe(new Uri(string.Format("http://{0}:{1}", mockProxyHost, mockProxyPort))); } - [TestMethod] - [ExpectedException(typeof(HttpException))] + [Fact] public async Task RestClient_Throws_exception_when_responsestatus_is_error() { // Arrange - var mockRestClient = new MockRestClient("/Country/GetList/", Enumerable.Empty(), ResponseStatus.Error, false); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Country/GetList")).Respond(HttpStatusCode.BadRequest); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); - var result = await apiClient.Countries.GetListAsync(); + var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + await Should.ThrowAsync(async () => + { + var result = await client.Countries.GetListAsync().ConfigureAwait(false); + }); } - [TestMethod] - [ExpectedException(typeof(HttpException))] + [Fact] public async Task RestClient_Throws_exception_when_responsestatus_is_timeout() { // Arrange - var mockRestClient = new MockRestClient("/Country/GetList/", Enumerable.Empty(), ResponseStatus.TimedOut, false); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Country/GetList")).Respond(HttpStatusCode.RequestTimeout); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); - var result = await apiClient.Countries.GetListAsync(); + var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + await Should.ThrowAsync(async () => + { + var result = await client.Countries.GetListAsync().ConfigureAwait(false); + }); } - [TestMethod] - [ExpectedException(typeof(HttpException))] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Country/GetList")).Respond("mediaType", ""); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); - var result = await apiClient.Countries.GetListAsync(); + var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + await Should.ThrowAsync(async () => + { + var result = await client.Countries.GetListAsync().ConfigureAwait(false); + }); } - [TestMethod] - [ExpectedException(typeof(CakeMailException))] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Country/GetList")).Respond(HttpStatusCode.OK, "", "dummy content"); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); - var result = await apiClient.Countries.GetListAsync(); + var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + await Should.ThrowAsync(async () => + { + var result = await client.Countries.GetListAsync().ConfigureAwait(false); + }); } - [TestMethod] - [ExpectedException(typeof(HttpException))] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Country/GetList")).Respond((HttpStatusCode)450); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); - var result = await apiClient.Countries.GetListAsync(); + var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + await Should.ThrowAsync(async () => + { + var result = await client.Countries.GetListAsync().ConfigureAwait(false); + }); } - [TestMethod] - [ExpectedException(typeof(HttpException))] + [Fact] 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); + 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 apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); - var result = await apiClient.Countries.GetListAsync(); + var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + await Should.ThrowAsync(async () => + { + var result = await client.Countries.GetListAsync().ConfigureAwait(false); + }); } - [TestMethod] - [ExpectedException(typeof(HttpException))] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Country/GetList")).Respond((HttpStatusCode)550); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); - var result = await apiClient.Countries.GetListAsync(); + var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + await Should.ThrowAsync(async () => + { + var result = await client.Countries.GetListAsync().ConfigureAwait(false); + }); } - [TestMethod] - [ExpectedException(typeof(HttpException))] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Country/GetList")).Respond((HttpStatusCode)600); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); - var result = await apiClient.Countries.GetListAsync(); + var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + await Should.ThrowAsync(async () => + { + var result = await client.Countries.GetListAsync().ConfigureAwait(false); + }); } - [TestMethod] - [ExpectedException(typeof(HttpException))] + [Fact] 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); + 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 apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); - var result = await apiClient.Countries.GetListAsync(); + var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + await Should.ThrowAsync(async () => + { + var result = await client.Countries.GetListAsync().ConfigureAwait(false); + }); } - [TestMethod] - [ExpectedException(typeof(CakeMailException))] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp + .Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Country/GetList")) + .Respond((HttpStatusCode)600, new StringContent("{\"status\":\"failure\",\"data\":\"An error has occured\"}", Encoding.UTF8, "application/json")); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); - var result = await apiClient.Countries.GetListAsync().ConfigureAwait(false); + var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + await Should.ThrowAsync(async () => + { + var result = await client.Countries.GetListAsync().ConfigureAwait(false); + }); } - [TestMethod] - [ExpectedException(typeof(CakeMailPostException))] + [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 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); + + var mockHttp = new MockHttpMessageHandler(); + mockHttp + .Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Campaign/Delete")) + .Respond((HttpStatusCode)600, new StringContent(jsonResponse, Encoding.UTF8, "application/json")); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); - var result = await apiClient.Campaigns.DeleteAsync(USER_KEY, campaignId, CLIENT_ID); + var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + await Should.ThrowAsync(async () => + { + var result = await client.Campaigns.DeleteAsync(USER_KEY, campaignId, CLIENT_ID); + }); } - [TestMethod] - [ExpectedException(typeof(CakeMailException))] + [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 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); + + var mockHttp = new MockHttpMessageHandler(); + mockHttp + .Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Campaign/Delete")) + .Respond((HttpStatusCode)600, new StringContent(jsonResponse, Encoding.UTF8, "application/json")); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); - var result = await apiClient.Campaigns.DeleteAsync(USER_KEY, campaignId, CLIENT_ID); + var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + await Should.ThrowAsync(async () => + { + var result = await client.Campaigns.DeleteAsync(USER_KEY, campaignId, CLIENT_ID); + }); } - [TestMethod] - [ExpectedException(typeof(CakeMailException))] + [Fact] public async Task RestClient_Throws_exception_when_reponse_does_not_contain_expected_property() { // Arrange @@ -275,18 +293,18 @@ public async Task RestClient_Throws_exception_when_reponse_does_not_contain_expe { "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); + + var mockHttp = new MockHttpMessageHandler(); + mockHttp + .Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/CreateCategory")) + .Respond((HttpStatusCode)600, new StringContent(jsonResponse, Encoding.UTF8, "application/json")); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); - var result = await apiClient.Templates.CreateCategoryAsync(USER_KEY, labels); + 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/Source/CakeMail.RestClient.UnitTests/Campaigns.cs b/Source/CakeMail.RestClient.UnitTests/Campaigns.cs index ec2553a..1c85aef 100644 --- a/Source/CakeMail.RestClient.UnitTests/Campaigns.cs +++ b/Source/CakeMail.RestClient.UnitTests/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 { - [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/Source/CakeMail.RestClient.UnitTests/Clients.cs b/Source/CakeMail.RestClient.UnitTests/Clients.cs index 95e97dc..17c42e7 100644 --- a/Source/CakeMail.RestClient.UnitTests/Clients.cs +++ b/Source/CakeMail.RestClient.UnitTests/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 { - [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/Source/CakeMail.RestClient.UnitTests/Countries.cs b/Source/CakeMail.RestClient.UnitTests/Countries.cs index a971434..c38d5e3 100644 --- a/Source/CakeMail.RestClient.UnitTests/Countries.cs +++ b/Source/CakeMail.RestClient.UnitTests/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 { - [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/Exceptions/CakeMailException.cs b/Source/CakeMail.RestClient.UnitTests/Exceptions/CakeMailException.cs index de5d1c3..a6d9afd 100644 --- a/Source/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 { - [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/Source/CakeMail.RestClient.UnitTests/Exceptions/CakeMailPostException.cs b/Source/CakeMail.RestClient.UnitTests/Exceptions/CakeMailPostException.cs index f78da92..a030c7d 100644 --- a/Source/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 { - [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/Source/CakeMail.RestClient.UnitTests/Exceptions/HttpException.cs b/Source/CakeMail.RestClient.UnitTests/Exceptions/HttpException.cs index f7b9fe5..72a50c5 100644 --- a/Source/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 { - [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/Source/CakeMail.RestClient.UnitTests/Lists.cs b/Source/CakeMail.RestClient.UnitTests/Lists.cs index 32aa4f9..e286915 100644 --- a/Source/CakeMail.RestClient.UnitTests/Lists.cs +++ b/Source/CakeMail.RestClient.UnitTests/Lists.cs @@ -1,21 +1,22 @@ using CakeMail.RestClient.Models; -using CakeMail.RestClient.Utilities; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using RestSharp; +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 { - [TestClass] 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; - [TestMethod] + [Fact] public async Task CreateList_with_minimal_parameters() { // Arrange @@ -23,25 +24,19 @@ public async Task CreateList_with_minimal_parameters() 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/Create/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.CreateAsync(MockRestClient.USER_KEY, name, defaultSenderName, defaultSenderAddress); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.CreateAsync(USER_KEY, name, defaultSenderName, defaultSenderAddress); // Assert - mockRestClient.Verify(); result.ShouldBe(listId); } - [TestMethod] + [Fact] public async Task CreateList_with_spampolicyaccepted() { // Arrange @@ -49,26 +44,19 @@ public async Task CreateList_with_spampolicyaccepted() 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/Create/")).Respond("application/json", 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); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.CreateAsync(USER_KEY, name, defaultSenderName, defaultSenderAddress, spamPolicyAccepted: true); // Assert - mockRestClient.Verify(); result.ShouldBe(listId); } - [TestMethod] + [Fact] public async Task CreateList_with_clientid() { // Arrange @@ -76,99 +64,77 @@ public async Task CreateList_with_clientid() 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/Create/")).Respond("application/json", 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); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.CreateAsync(USER_KEY, name, defaultSenderName, defaultSenderAddress, clientId: CLIENT_ID); // Assert - mockRestClient.Verify(); result.ShouldBe(listId); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/Delete/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.DeleteAsync(MockRestClient.USER_KEY, listId, null); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.DeleteAsync(USER_KEY, listId, null); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/Delete/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.DeleteAsync(MockRestClient.USER_KEY, listId, CLIENT_ID); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.DeleteAsync(USER_KEY, listId, CLIENT_ID); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetInfo/")).Respond("application/json", jsonResponse); // Actt - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetAsync(MockRestClient.USER_KEY, listId); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetAsync(USER_KEY, listId); // Assert - mockRestClient.Verify(); result.ShouldNotBeNull(); result.Id.ShouldBe(listId); } - [TestMethod] + [Fact] public async Task GetList_with_includestatistics_true() { await GetList_with_includestatistics(true).ConfigureAwait(false); } - [TestMethod] + [Fact] public async Task GetList_with_includestatistics_false() { await GetList_with_includestatistics(false).ConfigureAwait(false); @@ -178,32 +144,26 @@ 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetInfo/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetAsync(MockRestClient.USER_KEY, listId, includeStatistics: includeStatistics); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetAsync(USER_KEY, listId, includeStatistics: includeStatistics); // Assert - mockRestClient.Verify(); result.ShouldNotBeNull(); result.Id.ShouldBe(listId); } - [TestMethod] + [Fact] public async Task GetList_with_calculateengagement_true() { await GetList_with_calculateengagement(true).ConfigureAwait(false); } - [TestMethod] + [Fact] public async Task GetList_with_calculateengagement_false() { await GetList_with_calculateengagement(false).ConfigureAwait(false); @@ -213,899 +173,704 @@ 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetInfo/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetAsync(MockRestClient.USER_KEY, listId, calculateEngagement: calculateEngagement); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetAsync(USER_KEY, listId, calculateEngagement: calculateEngagement); // Assert - mockRestClient.Verify(); result.ShouldNotBeNull(); result.Id.ShouldBe(listId); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetInfo/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetAsync(MockRestClient.USER_KEY, listId, clientId: CLIENT_ID); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetAsync(USER_KEY, listId, clientId: CLIENT_ID); // Assert - mockRestClient.Verify(); result.ShouldNotBeNull(); result.Id.ShouldBe(listId); } - [TestMethod] + [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 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetList/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetListsAsync(MockRestClient.USER_KEY, status: status); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetListsAsync(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] + [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 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetList/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetListsAsync(MockRestClient.USER_KEY, name: name); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetListsAsync(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] + [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 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetList/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetListsAsync(MockRestClient.USER_KEY, sortBy: sortBy); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetListsAsync(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] + [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 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetList/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetListsAsync(MockRestClient.USER_KEY, sortDirection: sortDirection); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetListsAsync(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] + [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 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetList/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetListsAsync(MockRestClient.USER_KEY, limit: limit); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetListsAsync(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] + [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 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetList/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetListsAsync(MockRestClient.USER_KEY, offset: offset); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetListsAsync(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] + [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 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetList/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetListsAsync(MockRestClient.USER_KEY, clientId: CLIENT_ID); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetListsAsync(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] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetList/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetCountAsync(MockRestClient.USER_KEY, status: status); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetCountAsync(USER_KEY, status: status); // Assert - mockRestClient.Verify(); result.ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetList/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetCountAsync(MockRestClient.USER_KEY, name: name); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetCountAsync(USER_KEY, name: name); // Assert - mockRestClient.Verify(); result.ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetList/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetCountAsync(MockRestClient.USER_KEY, clientId: CLIENT_ID); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetCountAsync(USER_KEY, clientId: CLIENT_ID); // Assert - mockRestClient.Verify(); result.ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/SetInfo/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.UpdateAsync(MockRestClient.USER_KEY, listId, name: name); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.UpdateAsync(USER_KEY, listId, name: name); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/SetInfo/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.UpdateAsync(MockRestClient.USER_KEY, listId, language: language); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.UpdateAsync(USER_KEY, listId, language: language); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/SetInfo/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.UpdateAsync(MockRestClient.USER_KEY, listId, spamPolicyAccepted: true); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.UpdateAsync(USER_KEY, listId, spamPolicyAccepted: true); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/SetInfo/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.UpdateAsync(MockRestClient.USER_KEY, listId, spamPolicyAccepted: false); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.UpdateAsync(USER_KEY, listId, spamPolicyAccepted: false); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/SetInfo/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.UpdateAsync(MockRestClient.USER_KEY, listId, status: status); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.UpdateAsync(USER_KEY, listId, status: status); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/SetInfo/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.UpdateAsync(MockRestClient.USER_KEY, listId, senderName: senderName); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.UpdateAsync(USER_KEY, listId, senderName: senderName); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/SetInfo/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.UpdateAsync(MockRestClient.USER_KEY, listId, senderEmail: senderEmail); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.UpdateAsync(USER_KEY, listId, senderEmail: senderEmail); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/SetInfo/")).Respond("application/json", 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); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.UpdateAsync(USER_KEY, listId, goto_oi: goto_oi); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/SetInfo/")).Respond("application/json", 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); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.UpdateAsync(USER_KEY, listId, goto_di: goto_di); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/SetInfo/")).Respond("application/json", 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); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.UpdateAsync(USER_KEY, listId, goto_oo: goto_oo); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/SetInfo/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.UpdateAsync(MockRestClient.USER_KEY, listId, webhook: webhook); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.UpdateAsync(USER_KEY, listId, webhook: webhook); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/SetInfo/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.UpdateAsync(MockRestClient.USER_KEY, listId, clientId: CLIENT_ID); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.UpdateAsync(USER_KEY, listId, clientId: CLIENT_ID); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/EditStructure/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.AddFieldAsync(MockRestClient.USER_KEY, listId, name, fieldType); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.AddFieldAsync(USER_KEY, listId, name, fieldType); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/EditStructure/")).Respond("application/json", 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); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.AddFieldAsync(USER_KEY, listId, name, fieldType, CLIENT_ID); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/EditStructure/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.DeleteFieldAsync(MockRestClient.USER_KEY, listId, name); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.DeleteFieldAsync(USER_KEY, listId, name); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/EditStructure/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.DeleteFieldAsync(MockRestClient.USER_KEY, listId, name, CLIENT_ID); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.DeleteFieldAsync(USER_KEY, listId, name, CLIENT_ID); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetFields/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetFieldsAsync(MockRestClient.USER_KEY, listId); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetFieldsAsync(USER_KEY, listId); // Assert - mockRestClient.Verify(); result.ShouldNotBeNull(); result.Count().ShouldBe(3); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetFields/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetFieldsAsync(MockRestClient.USER_KEY, listId, CLIENT_ID); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetFieldsAsync(USER_KEY, listId, CLIENT_ID); // Assert - mockRestClient.Verify(); result.ShouldNotBeNull(); result.Count().ShouldBe(3); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetFields/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetFieldsAsync(MockRestClient.USER_KEY, listId, null); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetFieldsAsync(USER_KEY, listId, null); // Assert - mockRestClient.Verify(); result.ShouldNotBeNull(); result.Count().ShouldBe(0); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/AddTestEmail/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.AddTestEmailAsync(MockRestClient.USER_KEY, listId, email); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.AddTestEmailAsync(USER_KEY, listId, email); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/AddTestEmail/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.AddTestEmailAsync(MockRestClient.USER_KEY, listId, email, CLIENT_ID); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.AddTestEmailAsync(USER_KEY, listId, email, CLIENT_ID); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/DeleteTestEmail/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.DeleteTestEmailAsync(MockRestClient.USER_KEY, listId, email); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.DeleteTestEmailAsync(USER_KEY, listId, email); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/DeleteTestEmail/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.DeleteTestEmailAsync(MockRestClient.USER_KEY, listId, email, CLIENT_ID); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.DeleteTestEmailAsync(USER_KEY, listId, email, CLIENT_ID); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetTestEmails/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetTestEmailsAsync(MockRestClient.USER_KEY, listId); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetTestEmailsAsync(USER_KEY, listId); // Assert - mockRestClient.Verify(); result.ShouldNotBeNull(); result.Count().ShouldBe(2); result.ToArray()[0].ShouldBe(testEmail1); result.ToArray()[1].ShouldBe(testEmail2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetTestEmails/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetTestEmailsAsync(MockRestClient.USER_KEY, listId, CLIENT_ID); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetTestEmailsAsync(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] + [Fact] public async Task Subscribe_with_autoresponders_true() { await Subscribe_with_autoresponders(true).ConfigureAwait(false); } - [TestMethod] + [Fact] public async Task Subscribe_with_autoresponders_false() { await Subscribe_with_autoresponders(false).ConfigureAwait(false); @@ -1117,32 +882,25 @@ private async Task Subscribe_with_autoresponders(bool autoResponder) 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/SubscribeEmail/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.SubscribeAsync(MockRestClient.USER_KEY, listId, email, autoResponders: autoResponder); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.SubscribeAsync(USER_KEY, listId, email, autoResponders: autoResponder); // Assert - mockRestClient.Verify(); result.ShouldBe(subscriberId); } - [TestMethod] + [Fact] public async Task Subscribe_with_triggers_true() { await Subscribe_with_triggers(true).ConfigureAwait(false); } - [TestMethod] + [Fact] public async Task Subscribe_with_triggers_false() { await Subscribe_with_triggers(false).ConfigureAwait(false); @@ -1154,26 +912,19 @@ private async Task Subscribe_with_triggers(bool triggers) 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/SubscribeEmail/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.SubscribeAsync(MockRestClient.USER_KEY, listId, email, triggers: triggers); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.SubscribeAsync(USER_KEY, listId, email, triggers: triggers); // Assert - mockRestClient.Verify(); result.ShouldBe(subscriberId); } - [TestMethod] + [Fact] public async Task Subscribe_with_customfields() { // Arrange @@ -1188,62 +939,44 @@ public async Task Subscribe_with_customfields() 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/SubscribeEmail/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.SubscribeAsync(MockRestClient.USER_KEY, listId, email, customFields: customFields); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.SubscribeAsync(USER_KEY, listId, email, customFields: customFields); // Assert - mockRestClient.Verify(); result.ShouldBe(subscriberId); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/SubscribeEmail/")).Respond("application/json", 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); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.SubscribeAsync(USER_KEY, listId, email, clientId: CLIENT_ID); // Assert - mockRestClient.Verify(); result.ShouldBe(subscriberId); } - [TestMethod] + [Fact] public async Task Import_with_autoresponders_true() { await Import_with_autoresponders(true).ConfigureAwait(false); } - [TestMethod] + [Fact] public async Task Import_with_autoresponders_false() { await Import_with_autoresponders(false).ConfigureAwait(false); @@ -1258,35 +991,26 @@ private async Task Import_with_autoresponders(bool autoResponder) 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/Import/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.ImportAsync(MockRestClient.USER_KEY, listId, listMembers, autoResponders: autoResponder); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.ImportAsync(USER_KEY, listId, listMembers, autoResponders: autoResponder); // Assert - mockRestClient.Verify(); result.ShouldNotBeNull(); result.Count().ShouldBe(2); } - [TestMethod] + [Fact] public async Task Import_with_triggers_true() { await Import_with_triggers(true).ConfigureAwait(false); } - [TestMethod] + [Fact] public async Task Import_with_triggers_false() { await Import_with_triggers(false).ConfigureAwait(false); @@ -1301,29 +1025,20 @@ private async Task Import_with_triggers(bool triggers) 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/Import/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.ImportAsync(MockRestClient.USER_KEY, listId, listMembers, triggers: triggers); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.ImportAsync(USER_KEY, listId, listMembers, triggers: triggers); // Assert - mockRestClient.Verify(); result.ShouldNotBeNull(); result.Count().ShouldBe(2); } - [TestMethod] + [Fact] public async Task Import_with_customfields() { // Arrange @@ -1333,37 +1048,20 @@ public async Task Import_with_customfields() 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/Import/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.ImportAsync(MockRestClient.USER_KEY, listId, listMembers, autoResponders: true); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.ImportAsync(USER_KEY, listId, listMembers, autoResponders: true); // Assert - mockRestClient.Verify(); result.ShouldNotBeNull(); result.Count().ShouldBe(2); } - [TestMethod] + [Fact] public async Task Import_with_clientid() { // Arrange @@ -1373,273 +1071,207 @@ public async Task Import_with_clientid() 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/Import/")).Respond("application/json", 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); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.ImportAsync(USER_KEY, listId, listMembers, clientId: CLIENT_ID); // Assert - mockRestClient.Verify(); result.ShouldNotBeNull(); result.Count().ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/Import/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.ImportAsync(MockRestClient.USER_KEY, listId, listMembers); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.ImportAsync(USER_KEY, listId, listMembers); // Assert - mockRestClient.Verify(); result.ShouldNotBeNull(); result.Count().ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/UnsubscribeEmail/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.UnsubscribeAsync(MockRestClient.USER_KEY, listId, email, null); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.UnsubscribeAsync(USER_KEY, listId, email, null); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/UnsubscribeEmail/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.UnsubscribeAsync(MockRestClient.USER_KEY, listId, email, CLIENT_ID); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.UnsubscribeAsync(USER_KEY, listId, email, CLIENT_ID); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/UnsubscribeEmail/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.UnsubscribeAsync(MockRestClient.USER_KEY, listId, memberId, null); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.UnsubscribeAsync(USER_KEY, listId, memberId, null); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/UnsubscribeEmail/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.UnsubscribeAsync(MockRestClient.USER_KEY, listId, memberId, CLIENT_ID); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.UnsubscribeAsync(USER_KEY, listId, memberId, CLIENT_ID); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/DeleteRecord/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.DeleteMemberAsync(MockRestClient.USER_KEY, listId, memberId, null); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.DeleteMemberAsync(USER_KEY, listId, memberId, null); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/DeleteRecord/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.DeleteMemberAsync(MockRestClient.USER_KEY, listId, memberId, CLIENT_ID); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.DeleteMemberAsync(USER_KEY, listId, memberId, CLIENT_ID); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetRecord/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetMemberAsync(MockRestClient.USER_KEY, listId, memberId, null); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetMemberAsync(USER_KEY, listId, memberId, null); // Assert - mockRestClient.Verify(); result.ShouldNotBeNull(); result.Id.ShouldBe(memberId); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetRecord/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetMemberAsync(MockRestClient.USER_KEY, listId, memberId, CLIENT_ID); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetMemberAsync(USER_KEY, listId, memberId, CLIENT_ID); // Assert - mockRestClient.Verify(); result.ShouldNotBeNull(); result.Id.ShouldBe(memberId); } - [TestMethod] + [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 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/Show/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetMembersAsync(MockRestClient.USER_KEY, listId); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetMembersAsync(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] + [Fact] public async Task GetListMembers_with_status() { // Arrange @@ -1647,28 +1279,22 @@ public async Task GetListMembers_with_status() 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/Show/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetMembersAsync(MockRestClient.USER_KEY, listId, status: status); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetMembersAsync(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] + [Fact] public async Task GetListMembers_with_query() { // Arrange @@ -1676,28 +1302,22 @@ public async Task GetListMembers_with_query() 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/Show/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetMembersAsync(MockRestClient.USER_KEY, listId, query: query); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetMembersAsync(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] + [Fact] public async Task GetListMembers_with_sortby() { // Arrange @@ -1705,28 +1325,22 @@ public async Task GetListMembers_with_sortby() 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/Show/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetMembersAsync(MockRestClient.USER_KEY, listId, sortBy: sortBy); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetMembersAsync(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] + [Fact] public async Task GetListMembers_with_sortdirection() { // Arrange @@ -1734,28 +1348,22 @@ public async Task GetListMembers_with_sortdirection() 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/Show/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetMembersAsync(MockRestClient.USER_KEY, listId, sortDirection: sortDirection); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetMembersAsync(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] + [Fact] public async Task GetListMembers_with_limit() { // Arrange @@ -1763,28 +1371,22 @@ public async Task GetListMembers_with_limit() 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/Show/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetMembersAsync(MockRestClient.USER_KEY, listId, limit: limit); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetMembersAsync(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] + [Fact] public async Task GetListMembers_with_offset() { // Arrange @@ -1792,151 +1394,117 @@ public async Task GetListMembers_with_offset() 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/Show/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetMembersAsync(MockRestClient.USER_KEY, listId, offset: offset); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetMembersAsync(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] + [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 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/Show/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetMembersAsync(MockRestClient.USER_KEY, listId, clientId: CLIENT_ID); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetMembersAsync(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] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/Show/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetMembersCountAsync(MockRestClient.USER_KEY, listId); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetMembersCountAsync(USER_KEY, listId); // Assert - mockRestClient.Verify(); result.ShouldNotBeNull(); result.ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/Show/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetMembersCountAsync(MockRestClient.USER_KEY, listId, status: status); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetMembersCountAsync(USER_KEY, listId, status: status); // Assert - mockRestClient.Verify(); result.ShouldNotBeNull(); result.ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/Show/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetMembersCountAsync(MockRestClient.USER_KEY, listId, clientId: CLIENT_ID); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetMembersCountAsync(USER_KEY, listId, clientId: CLIENT_ID); // Assert - mockRestClient.Verify(); result.ShouldNotBeNull(); result.ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/UpdateRecord/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.UpdateMemberAsync(MockRestClient.USER_KEY, listId, memberId); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.UpdateMemberAsync(USER_KEY, listId, memberId); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] public async Task UpdateMember_with_customfields() { // Arrange @@ -1947,50 +1515,37 @@ public async Task UpdateMember_with_customfields() 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/UpdateRecord/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.UpdateMemberAsync(MockRestClient.USER_KEY, listId, memberId, customFields: customFields); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.UpdateMemberAsync(USER_KEY, listId, memberId, customFields: customFields); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/UpdateRecord/")).Respond("application/json", 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); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.UpdateMemberAsync(USER_KEY, listId, memberId, clientId: CLIENT_ID); // Assert - mockRestClient.Verify(); result.ShouldBeTrue(); } - [TestMethod] + [Fact] public async Task GetListLogs_with_minimal_parameters() { // Arrange @@ -1998,55 +1553,40 @@ public async Task GetListLogs_with_minimal_parameters() 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetLog/")).Respond("application/json", 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); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetLogsAsync(USER_KEY, listId, uniques: false, totals: false); // Assert - mockRestClient.Verify(); result.ShouldNotBeNull(); result.Count().ShouldBe(2); } - [TestMethod] + [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 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetLog/")).Respond("application/json", 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); + 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 - mockRestClient.Verify(); result.ShouldNotBeNull(); result.Count().ShouldBe(1); } - [TestMethod] + [Fact] public async Task GetListLogs_with_startdate() { // Arrange @@ -2054,28 +1594,20 @@ public async Task GetListLogs_with_startdate() 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetLog/")).Respond("application/json", 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); + 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 - mockRestClient.Verify(); result.ShouldNotBeNull(); result.Count().ShouldBe(2); } - [TestMethod] + [Fact] public async Task GetListLogs_with_enddate() { // Arrange @@ -2083,28 +1615,20 @@ public async Task GetListLogs_with_enddate() 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetLog/")).Respond("application/json", 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); + 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 - mockRestClient.Verify(); result.ShouldNotBeNull(); result.Count().ShouldBe(2); } - [TestMethod] + [Fact] public async Task GetListLogs_with_limit() { // Arrange @@ -2112,28 +1636,20 @@ public async Task GetListLogs_with_limit() 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetLog/")).Respond("application/json", 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); + 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 - mockRestClient.Verify(); result.ShouldNotBeNull(); result.Count().ShouldBe(2); } - [TestMethod] + [Fact] public async Task GetListLogs_with_offset() { // Arrange @@ -2141,281 +1657,198 @@ public async Task GetListLogs_with_offset() 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetLog/")).Respond("application/json", 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); + 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 - mockRestClient.Verify(); result.ShouldNotBeNull(); result.Count().ShouldBe(2); } - [TestMethod] + [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 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetLog/")).Respond("application/json", 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); + 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 - mockRestClient.Verify(); result.ShouldNotBeNull(); result.Count().ShouldBe(2); } - [TestMethod] + [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 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetLog/")).Respond("application/json", 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); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetLogsAsync(USER_KEY, listId, uniques: true, totals: false); // Assert - mockRestClient.Verify(); result.ShouldNotBeNull(); result.Count().ShouldBe(2); } - [TestMethod] + [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 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetLog/")).Respond("application/json", 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); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetLogsAsync(USER_KEY, listId, uniques: false, totals: true); // Assert - mockRestClient.Verify(); result.ShouldNotBeNull(); result.Count().ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetLog/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetLogsCountAsync(MockRestClient.USER_KEY, listId); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetLogsCountAsync(USER_KEY, listId); // Assert - mockRestClient.Verify(); result.ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetLog/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object); - var result = await apiClient.Lists.GetLogsCountAsync(MockRestClient.USER_KEY, listId, logType: logType); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetLogsCountAsync(USER_KEY, listId, logType: logType); // Assert - mockRestClient.Verify(); result.ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetLog/")).Respond("application/json", 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); + 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 - mockRestClient.Verify(); result.ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetLog/")).Respond("application/json", 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); + 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 - mockRestClient.Verify(); result.ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetLog/")).Respond("application/json", 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); + 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 - mockRestClient.Verify(); result.ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetLog/")).Respond("application/json", 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); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetLogsCountAsync(USER_KEY, listId, uniques: true, totals: false); // Assert - mockRestClient.Verify(); result.ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetLog/")).Respond("application/json", 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); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); + var result = await apiClient.Lists.GetLogsCountAsync(USER_KEY, listId, uniques: false, totals: true); // Assert - mockRestClient.Verify(); result.ShouldBe(2); } } diff --git a/Source/CakeMail.RestClient.UnitTests/Mailings.cs b/Source/CakeMail.RestClient.UnitTests/Mailings.cs index 27ba7bd..5885050 100644 --- a/Source/CakeMail.RestClient.UnitTests/Mailings.cs +++ b/Source/CakeMail.RestClient.UnitTests/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 { - [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/Permissions.cs b/Source/CakeMail.RestClient.UnitTests/Permissions.cs index e334ddc..75c3912 100644 --- a/Source/CakeMail.RestClient.UnitTests/Permissions.cs +++ b/Source/CakeMail.RestClient.UnitTests/Permissions.cs @@ -1,81 +1,65 @@ -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 { - [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] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Permission/SetPermissions/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.Permissions.SetUserPermissionsAsync(USER_KEY, userId, permissions, null); // Assert result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Permission/SetPermissions/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.Permissions.SetUserPermissionsAsync(USER_KEY, userId, permissions, CLIENT_ID); // Assert result.ShouldBeTrue(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Permission/GetPermissions/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.Permissions.GetUserPermissionsAsync(USER_KEY, userId); // Assert @@ -83,21 +67,17 @@ public async Task GetPermissions_with_minimal_parameters() result.Count().ShouldBe(3); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Permission/GetPermissions/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.Permissions.GetUserPermissionsAsync(USER_KEY, userId, CLIENT_ID); // Assert diff --git a/Source/CakeMail.RestClient.UnitTests/Relays.cs b/Source/CakeMail.RestClient.UnitTests/Relays.cs index 56ec479..536e791 100644 --- a/Source/CakeMail.RestClient.UnitTests/Relays.cs +++ b/Source/CakeMail.RestClient.UnitTests/Relays.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 { - [TestClass] public class RelaysTests { private const string API_KEY = "...dummy API key..."; @@ -23,242 +22,149 @@ public class RelaysTests private const string TEXT_CONTENT = "Hello Wolrd"; private const string SUBJECT = "Hello!"; - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Relay/Send/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + 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(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Relay/Send/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + 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(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Relay/Send/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + 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(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Relay/Send/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + 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(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Relay/Send/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + 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(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Relay/Send/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + 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(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Relay/Send/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + 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(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Relay/Send/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + 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(); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Relay/GetLogs/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.Relays.GetSentLogsAsync(USER_KEY); // Assert @@ -266,22 +172,19 @@ public async Task GetRelaySentLogs_with_minimal_parameters() result.Count().ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Relay/GetLogs/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.Relays.GetOpenLogsAsync(USER_KEY); // Assert @@ -289,22 +192,19 @@ public async Task GetRelayOpenLogs_with_minimal_parameters() result.Count().ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Relay/GetLogs/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.Relays.GetClickLogsAsync(USER_KEY); // Assert @@ -312,22 +212,19 @@ public async Task GetRelayClickLogs_with_minimal_parameters() result.Count().ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Relay/GetLogs/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.Relays.GetBounceLogsAsync(USER_KEY); // Assert @@ -335,23 +232,19 @@ public async Task GetRelayBounceLogs_with_minimal_parameters() result.Count().ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Relay/GetLogs/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.Relays.GetSentLogsAsync(USER_KEY, TRACKING_ID); // Assert @@ -359,7 +252,7 @@ public async Task GetRelayLogs_with_TRACKING_ID() result.Count().ShouldBe(2); } - [TestMethod] + [Fact] public async Task GetRelayLogs_with_startdate() { // Arrange @@ -367,16 +260,12 @@ public async Task GetRelayLogs_with_startdate() 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Relay/GetLogs/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.Relays.GetSentLogsAsync(USER_KEY, start: start); // Assert @@ -384,7 +273,7 @@ public async Task GetRelayLogs_with_startdate() result.Count().ShouldBe(2); } - [TestMethod] + [Fact] public async Task GetRelayLogs_with_enddate() { // Arrange @@ -392,16 +281,12 @@ public async Task GetRelayLogs_with_enddate() 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Relay/GetLogs/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.Relays.GetSentLogsAsync(USER_KEY, end: end); // Assert @@ -409,7 +294,7 @@ public async Task GetRelayLogs_with_enddate() result.Count().ShouldBe(2); } - [TestMethod] + [Fact] public async Task GetRelayLogs_with_limit() { // Arrange @@ -417,16 +302,12 @@ public async Task GetRelayLogs_with_limit() 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Relay/GetLogs/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.Relays.GetSentLogsAsync(USER_KEY, limit: limit); // Assert @@ -434,7 +315,7 @@ public async Task GetRelayLogs_with_limit() result.Count().ShouldBe(2); } - [TestMethod] + [Fact] public async Task GetRelayLogs_with_offset() { // Arrange @@ -442,16 +323,12 @@ public async Task GetRelayLogs_with_offset() 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Relay/GetLogs/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.Relays.GetSentLogsAsync(USER_KEY, offset: offset); // Assert @@ -459,23 +336,19 @@ public async Task GetRelayLogs_with_offset() result.Count().ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Relay/GetLogs/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.Relays.GetSentLogsAsync(USER_KEY, clientId: CLIENT_ID); // Assert diff --git a/Source/CakeMail.RestClient.UnitTests/Segments.cs b/Source/CakeMail.RestClient.UnitTests/Segments.cs index eebfb12..0f05f46 100644 --- a/Source/CakeMail.RestClient.UnitTests/Segments.cs +++ b/Source/CakeMail.RestClient.UnitTests/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 { - [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/SuppressionLists.cs b/Source/CakeMail.RestClient.UnitTests/SuppressionLists.cs index 45f3fa5..8dfe3a1 100644 --- a/Source/CakeMail.RestClient.UnitTests/SuppressionLists.cs +++ b/Source/CakeMail.RestClient.UnitTests/SuppressionLists.cs @@ -1,34 +1,29 @@ -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 { - [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] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/ImportEmails/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.AddEmailAddressesAsync(USER_KEY, emailAddresses); // Assert @@ -36,19 +31,16 @@ public async Task AddEmailAddressesToSuppressionList_with_minimal_parameters() result.Count().ShouldBe(3); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/ImportEmails/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.AddEmailAddressesAsync(USER_KEY, null); // Assert @@ -56,23 +48,17 @@ public async Task AddEmailAddressesToSuppressionList_with_null_array() result.Count().ShouldBe(3); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/ImportEmails/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.AddEmailAddressesAsync(USER_KEY, emailAddresses, CLIENT_ID); // Assert @@ -80,22 +66,17 @@ public async Task AddEmailAddressesToSuppressionList_with_clientid() result.Count().ShouldBe(3); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/ImportDomains/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.AddDomainsAsync(USER_KEY, domains); // Assert @@ -103,19 +84,16 @@ public async Task AddDomainsToSuppressionList_with_minimal_parameters() result.Count().ShouldBe(3); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/ImportDomains/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.AddDomainsAsync(USER_KEY, null); // Assert @@ -123,23 +101,17 @@ public async Task AddDomainsToSuppressionList_with_null_array() result.Count().ShouldBe(0); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/ImportDomains/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.AddDomainsAsync(USER_KEY, domains, CLIENT_ID); // Assert @@ -147,22 +119,17 @@ public async Task AddDomainsToSuppressionList_with_clientid() result.Count().ShouldBe(3); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/ImportLocalparts/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.AddLocalPartsAsync(USER_KEY, localParts); // Assert @@ -170,19 +137,16 @@ public async Task AddLocalPartsToSuppressionList_with_minimal_parameters() result.Count().ShouldBe(3); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/ImportLocalparts/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.AddLocalPartsAsync(USER_KEY, null); // Assert @@ -190,23 +154,17 @@ public async Task AddLocalPartsToSuppressionList_with_null_array() result.Count().ShouldBe(0); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/ImportLocalparts/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.AddLocalPartsAsync(USER_KEY, localParts, CLIENT_ID); // Assert @@ -214,22 +172,17 @@ public async Task AddLocalPartsToSuppressionList_with_clientid() result.Count().ShouldBe(3); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/DeleteEmails/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.RemoveEmailAddressesAsync(USER_KEY, emailAddresses); // Assert @@ -237,19 +190,16 @@ public async Task RemoveEmailAddressesFromSuppressionList_with_minimal_parameter result.Count().ShouldBe(3); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/DeleteEmails/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.RemoveEmailAddressesAsync(USER_KEY, null); // Assert @@ -257,23 +207,17 @@ public async Task RemoveEmailAddressesFromSuppressionList_with_null_array() result.Count().ShouldBe(0); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/DeleteEmails/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.RemoveEmailAddressesAsync(USER_KEY, emailAddresses, CLIENT_ID); // Assert @@ -281,22 +225,17 @@ public async Task RemoveEmailAddressesFromSuppressionList_with_clientid() result.Count().ShouldBe(3); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/DeleteDomains/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.RemoveDomainsAsync(USER_KEY, domains); // Assert @@ -304,19 +243,16 @@ public async Task RemoveDomainsFromSuppressionList_with_minimal_parameters() result.Count().ShouldBe(3); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/DeleteDomains/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.RemoveDomainsAsync(USER_KEY, null); // Assert @@ -324,23 +260,17 @@ public async Task RemoveDomainsFromSuppressionList_with_null_array() result.Count().ShouldBe(0); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/DeleteDomains/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.RemoveDomainsAsync(USER_KEY, domains, CLIENT_ID); // Assert @@ -348,22 +278,17 @@ public async Task RemoveDomainsFromSuppressionList_with_clientid() result.Count().ShouldBe(3); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/DeleteLocalparts/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.RemoveLocalPartsAsync(USER_KEY, localParts); // Assert @@ -371,19 +296,16 @@ public async Task RemoveLocalPartsFromSuppressionList_with_minimal_parameters() result.Count().ShouldBe(3); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/DeleteLocalparts/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.RemoveLocalPartsAsync(USER_KEY, null); // Assert @@ -391,23 +313,17 @@ public async Task RemoveLocalPartsFromSuppressionList_with_null_array() result.Count().ShouldBe(0); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/DeleteLocalparts/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.RemoveLocalPartsAsync(USER_KEY, localParts, CLIENT_ID); // Assert @@ -415,19 +331,16 @@ public async Task RemoveLocalPartsFromSuppressionList_with_clientid() result.Count().ShouldBe(3); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/ExportEmails/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.GetEmailAddressesAsync(USER_KEY); // Assert @@ -435,21 +348,17 @@ public async Task GetSuppressedEmailAddresses_with_minimal_parameters() result.Count().ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/ExportEmails/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.GetEmailAddressesAsync(USER_KEY, limit: limit); // Assert @@ -457,21 +366,17 @@ public async Task GetSuppressedEmailAddresses_with_limit() result.Count().ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/ExportEmails/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.GetEmailAddressesAsync(USER_KEY, offset: offset); // Assert @@ -479,20 +384,16 @@ public async Task GetSuppressedEmailAddresses_with_offset() result.Count().ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/ExportEmails/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.GetEmailAddressesAsync(USER_KEY, clientId: CLIENT_ID); // Assert @@ -500,19 +401,16 @@ public async Task GetSuppressedEmailAddresses_with_clientid() result.Count().ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/ExportDomains/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.GetDomainsAsync(USER_KEY); // Assert @@ -520,21 +418,17 @@ public async Task GetSuppressedDomains_with_minimal_parameters() result.Count().ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/ExportDomains/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.GetDomainsAsync(USER_KEY, limit: limit); // Assert @@ -542,21 +436,17 @@ public async Task GetSuppressedDomains_with_limit() result.Count().ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/ExportDomains/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.GetDomainsAsync(USER_KEY, offset: offset); // Assert @@ -564,20 +454,16 @@ public async Task GetSuppressedDomains_with_offset() result.Count().ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/ExportDomains/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.GetDomainsAsync(USER_KEY, clientId: CLIENT_ID); // Assert @@ -585,19 +471,16 @@ public async Task GetSuppressedDomains_with_clientid() result.Count().ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/ExportLocalparts/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.GetLocalPartsAsync(USER_KEY); // Assert @@ -605,21 +488,17 @@ public async Task GetSuppressedLocalParts_with_minimal_parameters() result.Count().ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/ExportLocalparts/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.GetLocalPartsAsync(USER_KEY, limit: limit); // Assert @@ -627,21 +506,17 @@ public async Task GetSuppressedLocalParts_with_limit() result.Count().ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/ExportLocalparts/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.GetLocalPartsAsync(USER_KEY, offset: offset); // Assert @@ -649,20 +524,16 @@ public async Task GetSuppressedLocalParts_with_offset() result.Count().ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/ExportLocalparts/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.GetLocalPartsAsync(USER_KEY, clientId: CLIENT_ID); // Assert @@ -670,117 +541,96 @@ public async Task GetSuppressedLocalParts_with_clientid() result.Count().ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/ExportEmails/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.GetEmailAddressesCountAsync(USER_KEY); // Assert result.ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/ExportEmails/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.GetEmailAddressesCountAsync(USER_KEY, clientId: CLIENT_ID); // Assert result.ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/ExportDomains/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.GetDomainsCountAsync(USER_KEY); // Assert result.ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/ExportDomains/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.GetDomainsCountAsync(USER_KEY, clientId: CLIENT_ID); // Assert result.ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/ExportLocalparts/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.GetLocalPartsCountAsync(USER_KEY); // Assert result.ShouldBe(2); } - [TestMethod] + [Fact] 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); + var mockHttp = new MockHttpMessageHandler(); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/ExportLocalparts/")).Respond("application/json", jsonResponse); // Act - var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object); + var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); var result = await apiClient.SuppressionLists.GetLocalPartsCountAsync(USER_KEY, clientId: CLIENT_ID); // Assert diff --git a/Source/CakeMail.RestClient.UnitTests/Templates.cs b/Source/CakeMail.RestClient.UnitTests/Templates.cs index 76c575e..66fa7ab 100644 --- a/Source/CakeMail.RestClient.UnitTests/Templates.cs +++ b/Source/CakeMail.RestClient.UnitTests/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 { - [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 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 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 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/Source/CakeMail.RestClient.UnitTests/Timezones.cs b/Source/CakeMail.RestClient.UnitTests/Timezones.cs index c607735..958a4ab 100644 --- a/Source/CakeMail.RestClient.UnitTests/Timezones.cs +++ b/Source/CakeMail.RestClient.UnitTests/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 { - [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/Source/CakeMail.RestClient.UnitTests/Triggers.cs b/Source/CakeMail.RestClient.UnitTests/Triggers.cs index d28131e..f13c3b8 100644 --- a/Source/CakeMail.RestClient.UnitTests/Triggers.cs +++ b/Source/CakeMail.RestClient.UnitTests/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 { - [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/Source/CakeMail.RestClient.UnitTests/Users.cs b/Source/CakeMail.RestClient.UnitTests/Users.cs index e921773..d8e3deb 100644 --- a/Source/CakeMail.RestClient.UnitTests/Users.cs +++ b/Source/CakeMail.RestClient.UnitTests/Users.cs @@ -1,21 +1,20 @@ 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 { - [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 @@ -23,25 +22,19 @@ public async Task CreateUser_with_minimal_parameters() 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); + 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); // Assert result.ShouldBe(userId); } - [TestMethod] + [Fact] public async Task CreateUser_with_firstname() { // Arrange @@ -50,26 +43,19 @@ public async Task CreateUser_with_firstname() 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 @@ -78,26 +64,19 @@ public async Task CreateUser_with_lastname() 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 @@ -106,26 +85,19 @@ public async Task CreateUser_with_title() 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 @@ -134,26 +106,19 @@ public async Task CreateUser_with_officephone() 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 @@ -162,26 +127,19 @@ public async Task CreateUser_with_mobilephone() 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 @@ -190,26 +148,19 @@ public async Task CreateUser_with_language() 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,25 +168,19 @@ 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 @@ -243,81 +188,63 @@ public async Task CreateUser_with_clientid() 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 +252,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 +270,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 +291,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 +313,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 +335,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 +357,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 +378,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 +660,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/Source/CakeMail.RestClient.UnitTests/Utilities/CakeMailDateTimeConverter.cs b/Source/CakeMail.RestClient.UnitTests/Utilities/CakeMailDateTimeConverter.cs index 682398d..6783925 100644 --- a/Source/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/Source/CakeMail.RestClient.UnitTests/Utilities/CakeMailIntegerBooleanConverter.cs b/Source/CakeMail.RestClient.UnitTests/Utilities/CakeMailIntegerBooleanConverter.cs index b05d3b4..33460e3 100644 --- a/Source/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/Source/CakeMail.RestClient.UnitTests/Utilities/ExtensionMethods.cs b/Source/CakeMail.RestClient.UnitTests/Utilities/ExtensionMethods.cs index dabe442..8c078b0 100644 --- a/Source/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 index b3b415d..7cb7808 100644 --- a/Source/CakeMail.RestClient.UnitTests/project.json +++ b/Source/CakeMail.RestClient.UnitTests/project.json @@ -1,22 +1,45 @@ { "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", - "RichardSzalay.MockHttp": "1.4.1", "Shouldly": "2.8.2", - "xunit": "2.2.0-beta4-build3444" + "RichardSzalay.MockHttp": "1.4.1" }, + "frameworks": { "netcoreapp1.0": { + "buildOptions": { + "define": [ "NETCORE" ] + }, + "imports": [ + "dnxcore50" + ], "dependencies": { "Microsoft.NETCore.App": { "type": "platform", - "version": "1.1.0" + "version": "1.0.1" + } + } + }, + "net452": { + "buildOptions": { + "define": [ "NETFULL" ] + }, + "dependencies": { + }, + "frameworkAssemblies": { + "System.Runtime": { + "type": "build" } - } } } From 7cbec6bb41175d1a4a73f8e40d2625cb4adf08c3 Mon Sep 17 00:00:00 2001 From: Jeremie Desautels Date: Thu, 9 Feb 2017 14:38:48 -0600 Subject: [PATCH 20/24] Move unit tests for 'Resources' to their own folder --- Source/CakeMail.RestClient.UnitTests/{ => Resources}/Campaigns.cs | 0 Source/CakeMail.RestClient.UnitTests/{ => Resources}/Clients.cs | 0 Source/CakeMail.RestClient.UnitTests/{ => Resources}/Countries.cs | 0 Source/CakeMail.RestClient.UnitTests/{ => Resources}/Lists.cs | 0 Source/CakeMail.RestClient.UnitTests/{ => Resources}/Mailings.cs | 0 .../CakeMail.RestClient.UnitTests/{ => Resources}/Permissions.cs | 0 Source/CakeMail.RestClient.UnitTests/{ => Resources}/Relays.cs | 0 Source/CakeMail.RestClient.UnitTests/{ => Resources}/Segments.cs | 0 .../{ => Resources}/SuppressionLists.cs | 0 Source/CakeMail.RestClient.UnitTests/{ => Resources}/Templates.cs | 0 Source/CakeMail.RestClient.UnitTests/{ => Resources}/Timezones.cs | 0 Source/CakeMail.RestClient.UnitTests/{ => Resources}/Triggers.cs | 0 Source/CakeMail.RestClient.UnitTests/{ => Resources}/Users.cs | 0 13 files changed, 0 insertions(+), 0 deletions(-) rename Source/CakeMail.RestClient.UnitTests/{ => Resources}/Campaigns.cs (100%) rename Source/CakeMail.RestClient.UnitTests/{ => Resources}/Clients.cs (100%) rename Source/CakeMail.RestClient.UnitTests/{ => Resources}/Countries.cs (100%) rename Source/CakeMail.RestClient.UnitTests/{ => Resources}/Lists.cs (100%) rename Source/CakeMail.RestClient.UnitTests/{ => Resources}/Mailings.cs (100%) rename Source/CakeMail.RestClient.UnitTests/{ => Resources}/Permissions.cs (100%) rename Source/CakeMail.RestClient.UnitTests/{ => Resources}/Relays.cs (100%) rename Source/CakeMail.RestClient.UnitTests/{ => Resources}/Segments.cs (100%) rename Source/CakeMail.RestClient.UnitTests/{ => Resources}/SuppressionLists.cs (100%) rename Source/CakeMail.RestClient.UnitTests/{ => Resources}/Templates.cs (100%) rename Source/CakeMail.RestClient.UnitTests/{ => Resources}/Timezones.cs (100%) rename Source/CakeMail.RestClient.UnitTests/{ => Resources}/Triggers.cs (100%) rename Source/CakeMail.RestClient.UnitTests/{ => Resources}/Users.cs (100%) diff --git a/Source/CakeMail.RestClient.UnitTests/Campaigns.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Campaigns.cs similarity index 100% rename from Source/CakeMail.RestClient.UnitTests/Campaigns.cs rename to Source/CakeMail.RestClient.UnitTests/Resources/Campaigns.cs diff --git a/Source/CakeMail.RestClient.UnitTests/Clients.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Clients.cs similarity index 100% rename from Source/CakeMail.RestClient.UnitTests/Clients.cs rename to Source/CakeMail.RestClient.UnitTests/Resources/Clients.cs diff --git a/Source/CakeMail.RestClient.UnitTests/Countries.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Countries.cs similarity index 100% rename from Source/CakeMail.RestClient.UnitTests/Countries.cs rename to Source/CakeMail.RestClient.UnitTests/Resources/Countries.cs diff --git a/Source/CakeMail.RestClient.UnitTests/Lists.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Lists.cs similarity index 100% rename from Source/CakeMail.RestClient.UnitTests/Lists.cs rename to Source/CakeMail.RestClient.UnitTests/Resources/Lists.cs diff --git a/Source/CakeMail.RestClient.UnitTests/Mailings.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Mailings.cs similarity index 100% rename from Source/CakeMail.RestClient.UnitTests/Mailings.cs rename to Source/CakeMail.RestClient.UnitTests/Resources/Mailings.cs diff --git a/Source/CakeMail.RestClient.UnitTests/Permissions.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Permissions.cs similarity index 100% rename from Source/CakeMail.RestClient.UnitTests/Permissions.cs rename to Source/CakeMail.RestClient.UnitTests/Resources/Permissions.cs diff --git a/Source/CakeMail.RestClient.UnitTests/Relays.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Relays.cs similarity index 100% rename from Source/CakeMail.RestClient.UnitTests/Relays.cs rename to Source/CakeMail.RestClient.UnitTests/Resources/Relays.cs diff --git a/Source/CakeMail.RestClient.UnitTests/Segments.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Segments.cs similarity index 100% rename from Source/CakeMail.RestClient.UnitTests/Segments.cs rename to Source/CakeMail.RestClient.UnitTests/Resources/Segments.cs diff --git a/Source/CakeMail.RestClient.UnitTests/SuppressionLists.cs b/Source/CakeMail.RestClient.UnitTests/Resources/SuppressionLists.cs similarity index 100% rename from Source/CakeMail.RestClient.UnitTests/SuppressionLists.cs rename to Source/CakeMail.RestClient.UnitTests/Resources/SuppressionLists.cs diff --git a/Source/CakeMail.RestClient.UnitTests/Templates.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Templates.cs similarity index 100% rename from Source/CakeMail.RestClient.UnitTests/Templates.cs rename to Source/CakeMail.RestClient.UnitTests/Resources/Templates.cs diff --git a/Source/CakeMail.RestClient.UnitTests/Timezones.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Timezones.cs similarity index 100% rename from Source/CakeMail.RestClient.UnitTests/Timezones.cs rename to Source/CakeMail.RestClient.UnitTests/Resources/Timezones.cs diff --git a/Source/CakeMail.RestClient.UnitTests/Triggers.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Triggers.cs similarity index 100% rename from Source/CakeMail.RestClient.UnitTests/Triggers.cs rename to Source/CakeMail.RestClient.UnitTests/Resources/Triggers.cs diff --git a/Source/CakeMail.RestClient.UnitTests/Users.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Users.cs similarity index 100% rename from Source/CakeMail.RestClient.UnitTests/Users.cs rename to Source/CakeMail.RestClient.UnitTests/Resources/Users.cs From 37bdf48b1b1e2de69c66cfcc79c00f53f99ff566 Mon Sep 17 00:00:00 2001 From: Jeremie Desautels Date: Sun, 12 Feb 2017 21:33:26 -0600 Subject: [PATCH 21/24] Switch to FluentHttpClient --- .../project.json | 13 +- .../CakeMailRestClientTests.cs | 68 ++--- .../Exceptions/CakeMailException.cs | 2 +- .../Exceptions/CakeMailPostException.cs | 2 +- .../Exceptions/HttpException.cs | 2 +- .../Resources/Campaigns.cs | 2 +- .../Resources/Clients.cs | 106 ++++---- .../Resources/Countries.cs | 2 +- .../Resources/Lists.cs | 184 +++++++------- .../Resources/Mailings.cs | 236 +++++++++--------- .../Resources/Permissions.cs | 10 +- .../Resources/Relays.cs | 48 ++-- .../Resources/Segments.cs | 40 +-- .../Resources/SuppressionLists.cs | 86 +++---- .../Resources/Templates.cs | 110 ++++---- .../Resources/Timezones.cs | 4 +- .../Resources/Triggers.cs | 184 +++++++------- .../Resources/Users.cs | 82 +++--- .../project.json | 2 +- .../CakeMail.RestClient/CakeMailRestClient.cs | 231 +++-------------- .../Exceptions/HttpException.cs | 4 +- .../ICakeMailRestClient.cs | 23 +- .../Resources/Campaigns.cs | 61 +++-- .../CakeMail.RestClient/Resources/Clients.cs | 68 +++-- .../Resources/Countries.cs | 27 +- Source/CakeMail.RestClient/Resources/Lists.cs | 210 ++++++++++------ .../CakeMail.RestClient/Resources/Mailings.cs | 182 +++++++++----- .../Resources/Permissions.cs | 28 ++- .../CakeMail.RestClient/Resources/Relays.cs | 42 ++-- .../CakeMail.RestClient/Resources/Segments.cs | 58 +++-- .../Resources/SuppressionLists.cs | 124 +++++---- .../Resources/Templates.cs | 137 ++++++---- .../Resources/Timezones.cs | 18 +- .../CakeMail.RestClient/Resources/Triggers.cs | 160 +++++++----- Source/CakeMail.RestClient/Resources/Users.cs | 57 +++-- .../Utilities/CakeMailDebugHandler.cs | 35 +++ .../Utilities/CakeMailErrorHandler.cs | 61 +++++ .../Utilities/ExtensionMethods.cs | 72 +++++- Source/CakeMail.RestClient/project.json | 2 +- 39 files changed, 1500 insertions(+), 1283 deletions(-) create mode 100644 Source/CakeMail.RestClient/Utilities/CakeMailDebugHandler.cs create mode 100644 Source/CakeMail.RestClient/Utilities/CakeMailErrorHandler.cs diff --git a/Source/CakeMail.RestClient.IntegrationTests/project.json b/Source/CakeMail.RestClient.IntegrationTests/project.json index 596ec07..22958b5 100644 --- a/Source/CakeMail.RestClient.IntegrationTests/project.json +++ b/Source/CakeMail.RestClient.IntegrationTests/project.json @@ -4,13 +4,12 @@ }, "dependencies": { "CakeMail.RestClient": { "target": "project" }, - "Microsoft.NETCore.App": { - "type": "platform", - "version": "1.1.0" - }, - "System.Net.NetworkInformation": "4.3.0", - "System.Net.Security": "4.3.0", - "System.Private.Networking": "4.0.0" + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.1.0" + }, + "System.Collections.NonGeneric": "4.3.0", + "System.Net.NetworkInformation": "4.3.0" }, "frameworks": { "netcoreapp1.0": { diff --git a/Source/CakeMail.RestClient.UnitTests/CakeMailRestClientTests.cs b/Source/CakeMail.RestClient.UnitTests/CakeMailRestClientTests.cs index 8cefacb..9b4c73e 100644 --- a/Source/CakeMail.RestClient.UnitTests/CakeMailRestClientTests.cs +++ b/Source/CakeMail.RestClient.UnitTests/CakeMailRestClientTests.cs @@ -1,5 +1,6 @@ using CakeMail.RestClient.Exceptions; using Moq; +using Newtonsoft.Json; using RichardSzalay.MockHttp; using Shouldly; using System; @@ -42,13 +43,11 @@ public void RestClient_constructor_with_ApiKey() var client = new CakeMailRestClient(API_KEY); var userAgent = client.UserAgent; var baseUrl = client.BaseUrl; - var timeout = client.Timeout; // 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")); - timeout.ShouldBe(5000); } [Fact] @@ -60,11 +59,9 @@ public void RestClient_constructor_with_IWebProxy() // Act var client = new CakeMailRestClient(API_KEY, mockProxy.Object); var baseUrl = client.BaseUrl; - var timeout = client.Timeout; // Assert baseUrl.ShouldBe(new Uri("https://api.wbsrvc.com")); - timeout.ShouldBe(5000); } [Fact] @@ -72,21 +69,18 @@ public void RestClient_constructor_with_HttpClient() { // Arrange var mockHost = "my.apiserver.com"; - var mockTimeout = 777; var mockHttp = new MockHttpMessageHandler(); var httpClient = new HttpClient(mockHttp); // Act - var client = new CakeMailRestClient(API_KEY, mockHost, mockTimeout, httpClient); + var client = new CakeMailRestClient(API_KEY, mockHost, httpClient); var baseUrl = client.BaseUrl; - var timeout = client.Timeout; // Assert mockHttp.VerifyNoOutstandingExpectation(); mockHttp.VerifyNoOutstandingRequest(); baseUrl.ShouldBe(new Uri($"https://{mockHost}")); - timeout.ShouldBe(mockTimeout); } [Fact] @@ -94,7 +88,7 @@ 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Country/GetList")).Respond(HttpStatusCode.BadRequest); // Act var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -109,7 +103,7 @@ 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Country/GetList")).Respond(HttpStatusCode.RequestTimeout); // Act var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -124,26 +118,11 @@ public async Task RestClient_Throws_exception_when_request_is_successful_but_res { // Arrange var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Country/GetList")).Respond("mediaType", ""); + 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_request_is_successful_but_response_contenttype_is_not_specified() - { - // Arrange - var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Country/GetList")).Respond(HttpStatusCode.OK, "", "dummy content"); - - // Act - var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); - await Should.ThrowAsync(async () => + await Should.ThrowAsync(async () => { var result = await client.Countries.GetListAsync().ConfigureAwait(false); }); @@ -154,7 +133,7 @@ public async Task RestClient_Throws_exception_when_responsescode_is_between_400_ { // Arrange var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Country/GetList")).Respond((HttpStatusCode)450); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Country/GetList")).Respond((HttpStatusCode)450); // Act var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -169,7 +148,7 @@ public async Task RestClient_Throws_exception_when_responsescode_is_between_400_ { // Arrange var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Country/GetList")).Respond((HttpStatusCode)450, new StringContent("dummy content", Encoding.UTF8, "application/json")); + 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()); @@ -184,7 +163,7 @@ public async Task RestClient_Throws_exception_when_responsescode_is_between_500_ { // Arrange var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Country/GetList")).Respond((HttpStatusCode)550); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Country/GetList")).Respond((HttpStatusCode)550); // Act var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -199,7 +178,7 @@ public async Task RestClient_Throws_exception_when_responsescode_is_greater_than { // Arrange var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Country/GetList")).Respond((HttpStatusCode)600); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Country/GetList")).Respond((HttpStatusCode)600); // Act var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -215,7 +194,7 @@ public async Task RestClient_Throws_exception_when_responsecode_is_greater_than_ // Arrange var mockHttp = new MockHttpMessageHandler(); mockHttp - .Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Country/GetList")) + .Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Country/GetList")) .Respond((HttpStatusCode)600, new StringContent("This is a bogus error message", Encoding.UTF8, "application/json")); // Act @@ -226,23 +205,6 @@ public async Task RestClient_Throws_exception_when_responsecode_is_greater_than_ }); } - [Fact] - public async Task RestClient_Throws_exception_when_cakemail_api_returns_failure() - { - // Arrange - var mockHttp = new MockHttpMessageHandler(); - mockHttp - .Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Country/GetList")) - .Respond((HttpStatusCode)600, new StringContent("{\"status\":\"failure\",\"data\":\"An error has occured\"}", 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() { @@ -253,7 +215,7 @@ public async Task RestClient_Throws_exception_when_cakemail_api_returns_failure_ var mockHttp = new MockHttpMessageHandler(); mockHttp .Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Campaign/Delete")) - .Respond((HttpStatusCode)600, new StringContent(jsonResponse, Encoding.UTF8, "application/json")); + .Respond((HttpStatusCode)200, new StringContent(jsonResponse, Encoding.UTF8, "application/json")); // Act var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -273,11 +235,11 @@ public async Task RestClient_Throws_exception_when_reponse_contains_invalid_json var mockHttp = new MockHttpMessageHandler(); mockHttp .Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Campaign/Delete")) - .Respond((HttpStatusCode)600, new StringContent(jsonResponse, Encoding.UTF8, "application/json")); + .Respond((HttpStatusCode)200, new StringContent(jsonResponse, Encoding.UTF8, "application/json")); // Act var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); - await Should.ThrowAsync(async () => + await Should.ThrowAsync(async () => { var result = await client.Campaigns.DeleteAsync(USER_KEY, campaignId, CLIENT_ID); }); @@ -297,7 +259,7 @@ public async Task RestClient_Throws_exception_when_reponse_does_not_contain_expe var mockHttp = new MockHttpMessageHandler(); mockHttp .Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/CreateCategory")) - .Respond((HttpStatusCode)600, new StringContent(jsonResponse, Encoding.UTF8, "application/json")); + .Respond((HttpStatusCode)200, new StringContent(jsonResponse, Encoding.UTF8, "application/json")); // Act var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); diff --git a/Source/CakeMail.RestClient.UnitTests/Exceptions/CakeMailException.cs b/Source/CakeMail.RestClient.UnitTests/Exceptions/CakeMailException.cs index a6d9afd..fc2e795 100644 --- a/Source/CakeMail.RestClient.UnitTests/Exceptions/CakeMailException.cs +++ b/Source/CakeMail.RestClient.UnitTests/Exceptions/CakeMailException.cs @@ -3,7 +3,7 @@ using System; using Xunit; -namespace CakeMail.RestClient.UnitTests.Utilities +namespace CakeMail.RestClient.UnitTests.Exceptions { public class CakeMailExceptionTests { diff --git a/Source/CakeMail.RestClient.UnitTests/Exceptions/CakeMailPostException.cs b/Source/CakeMail.RestClient.UnitTests/Exceptions/CakeMailPostException.cs index a030c7d..3ab74a4 100644 --- a/Source/CakeMail.RestClient.UnitTests/Exceptions/CakeMailPostException.cs +++ b/Source/CakeMail.RestClient.UnitTests/Exceptions/CakeMailPostException.cs @@ -3,7 +3,7 @@ using System; using Xunit; -namespace CakeMail.RestClient.UnitTests.Utilities +namespace CakeMail.RestClient.UnitTests.Exceptions { public class CakeMailPostExceptionTests { diff --git a/Source/CakeMail.RestClient.UnitTests/Exceptions/HttpException.cs b/Source/CakeMail.RestClient.UnitTests/Exceptions/HttpException.cs index 72a50c5..05c5120 100644 --- a/Source/CakeMail.RestClient.UnitTests/Exceptions/HttpException.cs +++ b/Source/CakeMail.RestClient.UnitTests/Exceptions/HttpException.cs @@ -4,7 +4,7 @@ using System.Net; using Xunit; -namespace CakeMail.RestClient.UnitTests.Utilities +namespace CakeMail.RestClient.UnitTests.Exceptions { public class HttpExceptionTests { diff --git a/Source/CakeMail.RestClient.UnitTests/Resources/Campaigns.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Campaigns.cs index 1c85aef..39d18dd 100644 --- a/Source/CakeMail.RestClient.UnitTests/Resources/Campaigns.cs +++ b/Source/CakeMail.RestClient.UnitTests/Resources/Campaigns.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; using Xunit; -namespace CakeMail.RestClient.UnitTests +namespace CakeMail.RestClient.UnitTests.Resources { public class CampaignsTests { diff --git a/Source/CakeMail.RestClient.UnitTests/Resources/Clients.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Clients.cs index 17c42e7..8f6e3a8 100644 --- a/Source/CakeMail.RestClient.UnitTests/Resources/Clients.cs +++ b/Source/CakeMail.RestClient.UnitTests/Resources/Clients.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; using Xunit; -namespace CakeMail.RestClient.UnitTests +namespace CakeMail.RestClient.UnitTests.Resources { public class ClientsTests { @@ -53,7 +53,7 @@ public async Task CreateClient_with_minimal_parameters() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", confirmationCode); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/Create/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/Create")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -71,7 +71,7 @@ public async Task CreateClient_with_minimal_parameters_and_contactsameasadmin_fa string confirmationCode = "... dummy confirmation code ..."; var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", confirmationCode); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/Create/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/Create")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -87,7 +87,7 @@ public async Task CreateClient_with_all_parameters() // Arrange var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", CONFIRMATION_CODE); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/Create/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/Create")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -103,7 +103,7 @@ public async Task CreateClient_admin_same_as_contact() // Arrange var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", CONFIRMATION_CODE); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/Create/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/Create")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -120,7 +120,7 @@ public async Task ConfirmClient() var confirmationId = "... dummy confirmation id ..."; 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 mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/Activate/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/Activate")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -138,7 +138,7 @@ public async Task GetClient_by_confirmationcode() var confirmationCode = "...dummy confirmation code..."; 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 mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/GetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/GetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -155,7 +155,7 @@ public async Task GetClient_with_minimal_parameters() // Arrange 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 mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/GetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/GetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -174,7 +174,7 @@ public async Task GetClient_with_startdate() var endDate = (DateTime?)null; 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 mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/GetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/GetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -193,7 +193,7 @@ public async Task GetClient_with_enddate() var endDate = new DateTime(2014, 12, 31, 23, 59, 59, 999, DateTimeKind.Utc); 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 mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/GetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/GetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -213,7 +213,7 @@ public async Task GetClients_with_status() 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 jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"clients\":[{0},{1}]}}}}", jsonClient1, jsonClient2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -233,7 +233,7 @@ public async Task GetClients_with_name() 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 jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"clients\":[{0},{1}]}}}}", jsonClient1, jsonClient2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -253,7 +253,7 @@ public async Task GetClients_with_sortBy() 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 jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"clients\":[{0},{1}]}}}}", jsonClient1, jsonClient2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -273,7 +273,7 @@ public async Task GetClients_with_sortdirection() 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 jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"clients\":[{0},{1}]}}}}", jsonClient1, jsonClient2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -293,7 +293,7 @@ public async Task GetClients_with_limit() 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 jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"clients\":[{0},{1}]}}}}", jsonClient1, jsonClient2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -313,7 +313,7 @@ public async Task GetClients_with_offset() 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 jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"clients\":[{0},{1}]}}}}", jsonClient1, jsonClient2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -332,7 +332,7 @@ public async Task GetClients_with_clientid() 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 jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"clients\":[{0},{1}]}}}}", jsonClient1, jsonClient2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -350,7 +350,7 @@ public async Task GetClientsCount_with_status() var status = ClientStatus.Active; var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -368,7 +368,7 @@ public async Task GetClientsCount_with_name() var name = "Dummy Client"; var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -385,7 +385,7 @@ public async Task GetClientsCount_with_clientid() // Arrange var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -403,7 +403,7 @@ public async Task UpdateClient_name() var name = "Fictitious Inc"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -420,7 +420,7 @@ public async Task UpdateClient_status() var status = ClientStatus.Active; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -437,7 +437,7 @@ public async Task UpdateClient_parentid() var parentId = 1L; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -454,7 +454,7 @@ public async Task UpdateClient_address1() var address1 = "123 1st Avenue"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -471,7 +471,7 @@ public async Task UpdateClient_address2() var address2 = "Suite 1000"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -488,7 +488,7 @@ public async Task UpdateClient_city() var city = "Mock City"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -505,7 +505,7 @@ public async Task UpdateClient_provinceid() var provinceId = "FL"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -522,7 +522,7 @@ public async Task UpdateClient_postalcode() var postalCode = "12345"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -539,7 +539,7 @@ public async Task UpdateClient_countryid() var countryId = "us"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -556,7 +556,7 @@ public async Task UpdateClient_website() var website = "www.fictitiouscompany.com"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -573,7 +573,7 @@ public async Task UpdateClient_phone() var phone = "111-111-1111"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -590,7 +590,7 @@ public async Task UpdateClient_fax() var fax = "222-222-2222"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -607,7 +607,7 @@ public async Task UpdateClient_autdomain() var authDomain = "md02.com"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -624,7 +624,7 @@ public async Task UpdateClient_bouncedomain() var bounceDomain = "bounce.fictitiouscompany.com"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -641,7 +641,7 @@ public async Task UpdateClient_dkimdomain() var dkimDomain = "md02.com"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -658,7 +658,7 @@ public async Task UpdateClient_doptinip() var doptinIp = "192.168.77.1"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -675,7 +675,7 @@ public async Task UpdateClient_forwarddomain() var forwardDomain = "http://forward.fictitiouscompany.com/"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -692,7 +692,7 @@ public async Task UpdateClient_forwardip() var forwardIp = "192.168.77.2"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -709,7 +709,7 @@ public async Task UpdateClient_ippool() var ipPool = "dummy"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -726,7 +726,7 @@ public async Task UpdateClient_mddomain() var mdDomain = "http://link.fictitiouscompany.com/"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -743,7 +743,7 @@ public async Task UpdateClient_isreseller_true() var isReseller = true; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -760,7 +760,7 @@ public async Task UpdateClient_isreseller_false() var isReseller = false; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -777,7 +777,7 @@ public async Task UpdateClient_currency() var currency = "USD"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -794,7 +794,7 @@ public async Task UpdateClient_plantype() var planType = "dummy plan"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -811,7 +811,7 @@ public async Task UpdateClient_mailinglimit() var mailingLimit = 10; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -828,7 +828,7 @@ public async Task UpdateClient_monthlimit() var monthLimit = 100; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -845,7 +845,7 @@ public async Task UpdateClient_contactlimit() var contactLimit = 1000; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -862,7 +862,7 @@ public async Task UpdateClient_defaultmailinglimit() var defaultMailingLimit = 10; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -879,7 +879,7 @@ public async Task UpdateClient_defaultmonthlimit() var defaultMonthLimit = 100; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -896,7 +896,7 @@ public async Task UpdateClient_defaultcontactlimit() var defaultContactLimit = 1000; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -912,7 +912,7 @@ public async Task ActivateClient() // Arrange var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -928,7 +928,7 @@ public async Task SuspendClient() // Arrange var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -944,7 +944,7 @@ public async Task DeleteClient() // Arrange var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); diff --git a/Source/CakeMail.RestClient.UnitTests/Resources/Countries.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Countries.cs index c38d5e3..b5b69d8 100644 --- a/Source/CakeMail.RestClient.UnitTests/Resources/Countries.cs +++ b/Source/CakeMail.RestClient.UnitTests/Resources/Countries.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; using Xunit; -namespace CakeMail.RestClient.UnitTests +namespace CakeMail.RestClient.UnitTests.Resources { public class CountriesTests { diff --git a/Source/CakeMail.RestClient.UnitTests/Resources/Lists.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Lists.cs index e286915..0d9706f 100644 --- a/Source/CakeMail.RestClient.UnitTests/Resources/Lists.cs +++ b/Source/CakeMail.RestClient.UnitTests/Resources/Lists.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; using Xunit; -namespace CakeMail.RestClient.UnitTests +namespace CakeMail.RestClient.UnitTests.Resources { public class ListsTests { @@ -26,7 +26,7 @@ public async Task CreateList_with_minimal_parameters() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Create")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -46,7 +46,7 @@ public async Task CreateList_with_spampolicyaccepted() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Create")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -66,7 +66,7 @@ public async Task CreateList_with_clientid() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Create")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -83,7 +83,7 @@ public async Task DeleteList_with_minimal_parameters() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Delete")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -100,7 +100,7 @@ public async Task DeleteList_with_clientid() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Delete")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -117,7 +117,7 @@ public async Task GetList_with_minimal_parameters() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetInfo")).Respond("application/json", jsonResponse); // Actt var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -146,7 +146,7 @@ private async Task GetList_with_includestatistics(bool includeStatistics) 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -175,7 +175,7 @@ private async Task GetList_with_calculateengagement(bool calculateEngagement) 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -193,7 +193,7 @@ public async Task GetList_with_clientid() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -213,7 +213,7 @@ public async Task GetLists_with_status() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -235,7 +235,7 @@ public async Task GetLists_with_name() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -257,7 +257,7 @@ public async Task GetLists_with_sortby() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -279,7 +279,7 @@ public async Task GetLists_with_sortdirection() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -301,7 +301,7 @@ public async Task GetLists_with_limit() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -323,7 +323,7 @@ public async Task GetLists_with_offset() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -344,7 +344,7 @@ public async Task GetLists_with_clientid() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -364,7 +364,7 @@ public async Task GetListsCount_with_status() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -381,7 +381,7 @@ public async Task GetListsCount_with_name() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -397,7 +397,7 @@ 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -415,7 +415,7 @@ public async Task UpdateList_name() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -433,7 +433,7 @@ public async Task UpdateList_language() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -450,7 +450,7 @@ public async Task UpdateList_spampolicy_accepted() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -467,7 +467,7 @@ public async Task UpdateList_spampolicy_declined() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -485,7 +485,7 @@ public async Task UpdateList_status() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -503,7 +503,7 @@ public async Task UpdateList_sendername() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -521,7 +521,7 @@ public async Task UpdateList_senderemail() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -539,7 +539,7 @@ public async Task UpdateList_gotooi() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -557,7 +557,7 @@ public async Task UpdateList_gotodi() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -575,7 +575,7 @@ public async Task UpdateList_gotooo() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -593,7 +593,7 @@ public async Task UpdateList_webhook() var webhook = "???"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -610,7 +610,7 @@ public async Task UpdateList_clientid() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -629,7 +629,7 @@ public async Task AddListField_with_minimal_parameters() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/EditStructure")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -648,7 +648,7 @@ public async Task AddListField_with_clientid() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/EditStructure")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -666,7 +666,7 @@ public async Task DeleteListField_with_minimal_parameters() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/EditStructure")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -684,7 +684,7 @@ public async Task DeleteListField_with_clientid() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/EditStructure")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -701,7 +701,7 @@ public async Task GetListFields_with_minimal_parameters() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetFields")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -719,7 +719,7 @@ public async Task GetListFields_with_clientid() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetFields")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -737,7 +737,7 @@ public async Task GetListFields_returns_null() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetFields")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -756,7 +756,7 @@ public async Task AddTestEmail_with_minimal_parameters() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/AddTestEmail")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -774,7 +774,7 @@ public async Task AddTestEmail_with_clientid() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/AddTestEmail")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -792,7 +792,7 @@ public async Task DeleteTestEmail_with_minimal_parameters() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/DeleteTestEmail")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -810,7 +810,7 @@ public async Task DeleteTestEmail_with_clientid() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/DeleteTestEmail")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -829,7 +829,7 @@ public async Task GetTestEmails_with_minimal_parameters() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetTestEmails")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -851,7 +851,7 @@ public async Task GetTestEmails_with_clientid() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetTestEmails")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -884,7 +884,7 @@ private async Task Subscribe_with_autoresponders(bool autoResponder) 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SubscribeEmail")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -914,7 +914,7 @@ private async Task Subscribe_with_triggers(bool triggers) 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SubscribeEmail")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -941,7 +941,7 @@ public async Task Subscribe_with_customfields() }; 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SubscribeEmail")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -960,7 +960,7 @@ public async Task Subscribe_with_clientid() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SubscribeEmail")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -993,7 +993,7 @@ private async Task Import_with_autoresponders(bool autoResponder) }; 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Import")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1027,7 +1027,7 @@ private async Task Import_with_triggers(bool triggers) }; 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Import")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1050,7 +1050,7 @@ public async Task Import_with_customfields() }; 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Import")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1073,7 +1073,7 @@ public async Task Import_with_clientid() }; 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Import")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1092,7 +1092,7 @@ public async Task Import_zero_subscribers() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Import")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1111,7 +1111,7 @@ public async Task Unsubscribe_by_email() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/UnsubscribeEmail")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1129,7 +1129,7 @@ public async Task Unsubscribe_by_email_with_clientid() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/UnsubscribeEmail")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1147,7 +1147,7 @@ public async Task Unsubscribe_by_memberid() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/UnsubscribeEmail")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1165,7 +1165,7 @@ public async Task Unsubscribe_by_memberid_with_clientid() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/UnsubscribeEmail")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1183,7 +1183,7 @@ public async Task DeleteListMember() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/DeleteRecord")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1201,7 +1201,7 @@ public async Task DeleteListMember_with_clientid() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/DeleteRecord")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1219,7 +1219,7 @@ public async Task GetListMember() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetRecord")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1238,7 +1238,7 @@ public async Task GetListMember_with_clientid() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetRecord")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1258,7 +1258,7 @@ public async Task GetListMembers_with_minimal_parameters() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Show")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1281,7 +1281,7 @@ public async Task GetListMembers_with_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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Show")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1304,7 +1304,7 @@ public async Task GetListMembers_with_query() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Show")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1327,7 +1327,7 @@ public async Task GetListMembers_with_sortby() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Show")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1350,7 +1350,7 @@ public async Task GetListMembers_with_sortdirection() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Show")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1373,7 +1373,7 @@ public async Task GetListMembers_with_limit() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Show")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1396,7 +1396,7 @@ public async Task GetListMembers_with_offset() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Show")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1418,7 +1418,7 @@ public async Task GetListMembers_with_clientid() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Show")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1438,7 +1438,7 @@ public async Task GetListMembersCount_with_minimal_parameters() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Show")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1457,7 +1457,7 @@ public async Task GetListMembersCount_with_status() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Show")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1475,7 +1475,7 @@ public async Task GetListMembersCount_with_clientid() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Show")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1494,7 +1494,7 @@ public async Task UpdateMember_with_minimal_parameters() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/UpdateRecord")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1517,7 +1517,7 @@ public async Task UpdateMember_with_customfields() }; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/UpdateRecord/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/UpdateRecord")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1535,7 +1535,7 @@ public async Task UpdateMember_with_clientid() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/UpdateRecord")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1555,7 +1555,7 @@ public async Task GetListLogs_with_minimal_parameters() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1575,7 +1575,7 @@ public async Task GetListLogs_with_logtype() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1596,7 +1596,7 @@ public async Task GetListLogs_with_startdate() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1617,7 +1617,7 @@ public async Task GetListLogs_with_enddate() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1638,7 +1638,7 @@ public async Task GetListLogs_with_limit() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1659,7 +1659,7 @@ public async Task GetListLogs_with_offset() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1679,7 +1679,7 @@ public async Task GetListLogs_with_clientid() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1699,7 +1699,7 @@ public async Task GetListLogs_with_uniques_true() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1719,7 +1719,7 @@ public async Task GetListLogs_with_totals_true() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1737,7 +1737,7 @@ public async Task GetListLogsCount_with_minimal_parameters() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1755,7 +1755,7 @@ public async Task GetListLogsCount_with_logtype() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1773,7 +1773,7 @@ public async Task GetListLogsCount_with_startdate() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1791,7 +1791,7 @@ public async Task GetListLogsCount_with_enddate() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1808,7 +1808,7 @@ public async Task GetListLogsCount_with_clientid() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1825,7 +1825,7 @@ public async Task GetListLogsCount_with_uniques_true() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1842,7 +1842,7 @@ public async Task GetListLogsCount_with_totals_true() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); diff --git a/Source/CakeMail.RestClient.UnitTests/Resources/Mailings.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Mailings.cs index 5885050..149da31 100644 --- a/Source/CakeMail.RestClient.UnitTests/Resources/Mailings.cs +++ b/Source/CakeMail.RestClient.UnitTests/Resources/Mailings.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; using Xunit; -namespace CakeMail.RestClient.UnitTests +namespace CakeMail.RestClient.UnitTests.Resources { public class MailingsTests { @@ -23,7 +23,7 @@ public async Task CreateMailing_with_minimal_parameters() var mailingId = 123L; var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", mailingId); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/Create/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Create")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -41,7 +41,7 @@ public async Task CreateMailing_without_type() var mailingId = 123L; var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", mailingId); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/Create/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Create")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -61,7 +61,7 @@ public async Task CreateMailing_with_campaignid() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", mailingId); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/Create/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Create")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -81,7 +81,7 @@ public async Task CreateMailing_with_type() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", mailingId); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/Create/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Create")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -101,7 +101,7 @@ public async Task CreateMailing_with_recurringid() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", mailingId); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/Create/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Create")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -121,7 +121,7 @@ public async Task CreateMailing_with_encoding() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", mailingId); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/Create/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Create")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -141,7 +141,7 @@ public async Task CreateMailing_with_trasnferencoding() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", mailingId); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/Create/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Create")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -160,7 +160,7 @@ public async Task CreateMailing_with_clientid() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", mailingId); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/Create/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Create")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -178,7 +178,7 @@ public async Task DeleteMailing_with_minimal_parameters() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/Delete/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Delete")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -196,7 +196,7 @@ public async Task DeleteMailing_with_clientid() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/Delete/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Delete")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -214,7 +214,7 @@ public async Task GetMailing_with_minimal_parameters() 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 mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -233,7 +233,7 @@ public async Task GetMailing_with_clientid() 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 mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -253,7 +253,7 @@ public async Task GetMailings_with_minimal_parameters() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"mailings\":[{0},{1}]}}}}", jsonMailing1, jsonMailing2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -276,7 +276,7 @@ public async Task GetMailings_with_status() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"mailings\":[{0},{1}]}}}}", jsonMailing1, jsonMailing2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -299,7 +299,7 @@ public async Task GetMailings_with_type() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"mailings\":[{0},{1}]}}}}", jsonMailing1, jsonMailing2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -322,7 +322,7 @@ public async Task GetMailings_with_name() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"mailings\":[{0},{1}]}}}}", jsonMailing1, jsonMailing2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -345,7 +345,7 @@ public async Task GetMailings_with_listid() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"mailings\":[{0},{1}]}}}}", jsonMailing1, jsonMailing2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -368,7 +368,7 @@ public async Task GetMailings_with_campaignid() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"mailings\":[{0},{1}]}}}}", jsonMailing1, jsonMailing2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -391,7 +391,7 @@ public async Task GetMailings_with_recurringid() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"mailings\":[{0},{1}]}}}}", jsonMailing1, jsonMailing2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -414,7 +414,7 @@ public async Task GetMailings_with_start() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"mailings\":[{0},{1}]}}}}", jsonMailing1, jsonMailing2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -437,7 +437,7 @@ public async Task GetMailings_with_end() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"mailings\":[{0},{1}]}}}}", jsonMailing1, jsonMailing2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -460,7 +460,7 @@ public async Task GetMailings_with_sortby() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"mailings\":[{0},{1}]}}}}", jsonMailing1, jsonMailing2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -483,7 +483,7 @@ public async Task GetMailings_with_sortdirection() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"mailings\":[{0},{1}]}}}}", jsonMailing1, jsonMailing2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -506,7 +506,7 @@ public async Task GetMailings_with_limit() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"mailings\":[{0},{1}]}}}}", jsonMailing1, jsonMailing2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -529,7 +529,7 @@ public async Task GetMailings_with_offset() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"mailings\":[{0},{1}]}}}}", jsonMailing1, jsonMailing2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -551,7 +551,7 @@ public async Task GetMailings_with_clientid() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"mailings\":[{0},{1}]}}}}", jsonMailing1, jsonMailing2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -570,7 +570,7 @@ public async Task GetMailingsCount_with_minimal_parameters() // Arrange var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -588,7 +588,7 @@ public async Task GetMailingsCount_with_status() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -606,7 +606,7 @@ public async Task GetMailingsCount_with_type() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -624,7 +624,7 @@ public async Task GetMailingsCount_with_name() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -642,7 +642,7 @@ public async Task GetMailingsCount_with_listid() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -660,7 +660,7 @@ public async Task GetMailingsCount_with_campaignid() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -678,7 +678,7 @@ public async Task GetMailingsCount_with_recurringid() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -696,7 +696,7 @@ public async Task GetMailingsCount_with_start() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -714,7 +714,7 @@ public async Task GetMailingsCount_with_end() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -730,7 +730,7 @@ public async Task GetMailingsCount_with_clientid() // Arrange var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -748,7 +748,7 @@ public async Task UpdateMailing_with_minimal_parameters() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -767,7 +767,7 @@ public async Task UpdateMailing_with_campaignid() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -786,7 +786,7 @@ public async Task UpdateMailing_with_listid() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -805,7 +805,7 @@ public async Task UpdateMailing_with_sublistid() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -824,7 +824,7 @@ public async Task UpdateMailing_with_name() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -843,7 +843,7 @@ public async Task UpdateMailing_with_type() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -862,7 +862,7 @@ public async Task UpdateMailing_with_encoding() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -881,7 +881,7 @@ public async Task UpdateMailing_with_transferencoding() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -900,7 +900,7 @@ public async Task UpdateMailing_with_subject() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -919,7 +919,7 @@ public async Task UpdateMailing_with_senderemail() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -938,7 +938,7 @@ public async Task UpdateMailing_with_sendername() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -957,7 +957,7 @@ public async Task UpdateMailing_with_replyto() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -976,7 +976,7 @@ public async Task UpdateMailing_with_htmlcontent() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -995,7 +995,7 @@ public async Task UpdateMailing_with_textcontent() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1013,7 +1013,7 @@ public async Task UpdateMailing_with_trackopens_true() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1031,7 +1031,7 @@ public async Task UpdateMailing_with_trackopens_false() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1049,7 +1049,7 @@ public async Task UpdateMailing_with_trackclicksinhtml_true() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1067,7 +1067,7 @@ public async Task UpdateMailing_with_trackclicksinhtml_false() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1085,7 +1085,7 @@ public async Task UpdateMailing_with_trackclicksintext_true() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1103,7 +1103,7 @@ public async Task UpdateMailing_with_trackclicksintext_false() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1122,7 +1122,7 @@ public async Task UpdateMailing_with_trackingparameters() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1141,7 +1141,7 @@ public async Task UpdateMailing_with_endingon() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1160,7 +1160,7 @@ public async Task UpdateMailing_with_maxrecurrences() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1179,7 +1179,7 @@ public async Task UpdateMailing_with_recurringconditions() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1197,7 +1197,7 @@ public async Task UpdateMailing_with_clientid() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1216,7 +1216,7 @@ public async Task SendMailingTestEmail_with_minimal_parameters() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/SendTestEmail/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SendTestEmail")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1235,7 +1235,7 @@ public async Task SendMailingTestEmail_with_separated_true() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/SendTestEmail/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SendTestEmail")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1254,7 +1254,7 @@ public async Task SendMailingTestEmail_with_clientid() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/SendTestEmail/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SendTestEmail")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1272,7 +1272,7 @@ public async Task GetMailingRawEmailMessage_with_minimal_parameters() var jsonResponse = "{\"status\":\"success\",\"data\":{\"subject\":\"This is a simple message\",\"message\":\"...dummy content...\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetEmailMessage/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetEmailMessage")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1291,7 +1291,7 @@ public async Task GetMailingRawEmailMessage_with_clientid() var jsonResponse = "{\"status\":\"success\",\"data\":{\"subject\":\"This is a simple message\",\"message\":\"...dummy content...\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetEmailMessage/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetEmailMessage")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1310,7 +1310,7 @@ public async Task GetMailingRawHtml_with_minimal_parameters() var jsonResponse = "{\"status\":\"success\",\"data\":\"...dummy content...\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetHtmlMessage/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetHtmlMessage")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1328,7 +1328,7 @@ public async Task GetMailingRawHtml_with_clientid() var jsonResponse = "{\"status\":\"success\",\"data\":\"...dummy content...\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetHtmlMessage/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetHtmlMessage")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1346,7 +1346,7 @@ public async Task GetMailingRawText_with_minimal_parameters() var jsonResponse = "{\"status\":\"success\",\"data\":\"...dummy content...\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetTextMessage/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetTextMessage")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1364,7 +1364,7 @@ public async Task GetMailingRawText_with_clientid() var jsonResponse = "{\"status\":\"success\",\"data\":\"...dummy content...\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetTextMessage/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetTextMessage")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1382,7 +1382,7 @@ public async Task ScheduleMailing_with_minimal_parameters() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/Schedule/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Schedule")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1401,7 +1401,7 @@ public async Task ScheduleMailing_with_date() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/Schedule/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Schedule")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1419,7 +1419,7 @@ public async Task ScheduleMailing_with_clientid() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/Schedule/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Schedule")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1437,7 +1437,7 @@ public async Task UnscheduleMailing_with_minimal_parameters() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/Unschedule/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Unschedule")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1455,7 +1455,7 @@ public async Task UnscheduleMailing_with_clientid() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/Unschedule/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Unschedule")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1473,7 +1473,7 @@ public async Task SuspendMailing_with_minimal_parameters() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/Suspend/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Suspend")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1491,7 +1491,7 @@ public async Task SuspendMailing_with_clientid() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/Suspend/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Suspend")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1509,7 +1509,7 @@ public async Task ResumeMailing_with_minimal_parameters() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/Resume/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Resume")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1527,7 +1527,7 @@ public async Task ResumeMailing_with_clientid() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/Resume/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Resume")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1548,7 +1548,7 @@ public async Task GetMailingLogs_with_minimal_parameters() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1570,7 +1570,7 @@ public async Task GetMailingLogs_with_logtype() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0}]}}}}", sentLog); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1592,7 +1592,7 @@ public async Task GetMailingLogs_with_listmemberid() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0}]}}}}", sentLog); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1615,7 +1615,7 @@ public async Task GetMailingLogs_with_startdate() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1638,7 +1638,7 @@ public async Task GetMailingLogs_with_enddate() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1661,7 +1661,7 @@ public async Task GetMailingLogs_with_limit() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1684,7 +1684,7 @@ public async Task GetMailingLogs_with_offset() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1706,7 +1706,7 @@ public async Task GetMailingLogs_with_clientid() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1728,7 +1728,7 @@ public async Task GetMailingLogs_with_uniques_true() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1750,7 +1750,7 @@ public async Task GetMailingLogs_with_totals_true() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1769,7 +1769,7 @@ public async Task GetMailingLogsCount_with_minimal_parameters() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1789,7 +1789,7 @@ public async Task GetMailingLogsCount_with_logtype() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1809,7 +1809,7 @@ public async Task GetMailingLogsCount_with_listmemberid() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1828,7 +1828,7 @@ public async Task GetMailingLogsCount_with_uniques_true() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1847,7 +1847,7 @@ public async Task GetMailingLogsCount_with_totals_true() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1867,7 +1867,7 @@ public async Task GetMailingLogsCount_with_startdate() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1887,7 +1887,7 @@ public async Task GetMailingLogsCount_with_enddate() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1906,7 +1906,7 @@ public async Task GetMailingLogsCount_with_clientid() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1928,7 +1928,7 @@ public async Task GetMailingLinks_with_minimal_parameters() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonLink1, jsonLink2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLinks/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinks")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1951,7 +1951,7 @@ public async Task GetMailingLinks_with_limit() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonLink1, jsonLink2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLinks/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinks")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1974,7 +1974,7 @@ public async Task GetMailingLinks_with_offset() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonLink1, jsonLink2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLinks/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinks")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1996,7 +1996,7 @@ public async Task GetMailingLinks_with_clientid() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonLink1, jsonLink2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLinks/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinks")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -2015,7 +2015,7 @@ public async Task GetMailingLinksCount_with_minimal_parameters() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLinks/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinks")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -2033,7 +2033,7 @@ public async Task GetMailingLinksCount_with_clientid() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLinks/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinks")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -2051,7 +2051,7 @@ public async Task GetMailingLink_with_minimal_parameters() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"status\":\"active\",\"link_to\":\"http://www.fictitiouscompany.com.com/\"}}}}", linkId); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLinkInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinkInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -2070,7 +2070,7 @@ public async Task GetMailingLink_with_clientid() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"status\":\"active\",\"link_to\":\"http://www.fictitiouscompany.com.com/\"}}}}", linkId); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLinkInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinkInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -2092,7 +2092,7 @@ public async Task GetMailingLinksWithStats_with_minimal_parameters() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonLink1, jsonLink2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLinksLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinksLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -2115,7 +2115,7 @@ public async Task GetMailingLinksWithStats_with_start() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonLink1, jsonLink2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLinksLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinksLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -2138,7 +2138,7 @@ public async Task GetMailingLinksWithStats_with_end() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonLink1, jsonLink2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLinksLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinksLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -2161,7 +2161,7 @@ public async Task GetMailingLinksWithStats_with_limit() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonLink1, jsonLink2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLinksLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinksLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -2184,7 +2184,7 @@ public async Task GetMailingLinksWithStats_with_offset() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonLink1, jsonLink2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLinksLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinksLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -2206,7 +2206,7 @@ public async Task GetMailingLinksWithStats_with_clientid() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonLink1, jsonLink2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLinksLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinksLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -2225,7 +2225,7 @@ public async Task GetMailingLinksWithStatsCount_with_minimal_parameters() var jsonResponse = "{\"status\":\"success\",\"data\":{\"links\":[],\"count\":\"3\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLinksLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinksLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -2247,7 +2247,7 @@ public async Task GetMailingLinksWithStatsCount_with_start() var jsonResponse = "{\"status\":\"success\",\"data\":{\"links\":[],\"count\":\"3\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLinksLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinksLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -2266,7 +2266,7 @@ public async Task GetMailingLinksWithStatsCount_with_end() var jsonResponse = "{\"status\":\"success\",\"data\":{\"links\":[],\"count\":\"3\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLinksLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinksLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -2285,7 +2285,7 @@ public async Task GetMailingLinksWithStatsCount_with_limit() var jsonResponse = "{\"status\":\"success\",\"data\":{\"links\":[],\"count\":\"3\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLinksLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinksLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -2304,7 +2304,7 @@ public async Task GetMailingLinksWithStatsCount_with_offset() var jsonResponse = "{\"status\":\"success\",\"data\":{\"links\":[],\"count\":\"3\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLinksLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinksLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -2322,7 +2322,7 @@ public async Task GetMailingLinksWithStatsCount_with_clientid() var jsonResponse = "{\"status\":\"success\",\"data\":{\"links\":[],\"count\":\"3\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Mailing/GetLinksLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinksLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); diff --git a/Source/CakeMail.RestClient.UnitTests/Resources/Permissions.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Permissions.cs index 75c3912..8ab6dc1 100644 --- a/Source/CakeMail.RestClient.UnitTests/Resources/Permissions.cs +++ b/Source/CakeMail.RestClient.UnitTests/Resources/Permissions.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; using Xunit; -namespace CakeMail.RestClient.UnitTests +namespace CakeMail.RestClient.UnitTests.Resources { public class PermissionsTests { @@ -21,7 +21,7 @@ public async Task SetPermissions_with_minimal_parameters() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Permission/SetPermissions")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -39,7 +39,7 @@ public async Task SetPermissions_with_customerid() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Permission/SetPermissions")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -56,7 +56,7 @@ public async Task GetPermissions_with_minimal_parameters() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Permission/GetPermissions")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -74,7 +74,7 @@ public async Task GetPermissions_with_clientid() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Permission/GetPermissions")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); diff --git a/Source/CakeMail.RestClient.UnitTests/Resources/Relays.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Relays.cs index 536e791..c1c7539 100644 --- a/Source/CakeMail.RestClient.UnitTests/Resources/Relays.cs +++ b/Source/CakeMail.RestClient.UnitTests/Resources/Relays.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; using Xunit; -namespace CakeMail.RestClient.UnitTests +namespace CakeMail.RestClient.UnitTests.Resources { public class RelaysTests { @@ -28,7 +28,7 @@ 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/Send")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -44,7 +44,7 @@ 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/Send")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -61,7 +61,7 @@ public async Task SendRelay_with_encoding() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/Send")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -77,7 +77,7 @@ 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/Send")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -93,7 +93,7 @@ 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/Send")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -109,7 +109,7 @@ 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/Send")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -126,7 +126,7 @@ public async Task SendTrackedRelay_with_encoding() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/Send")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -142,7 +142,7 @@ 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/Send")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -156,12 +156,11 @@ public async Task SendTrackedRelay_with_clientid() 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 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/GetLogs")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -176,12 +175,11 @@ public async Task GetRelaySentLogs_with_minimal_parameters() 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 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/GetLogs")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -196,12 +194,11 @@ public async Task GetRelayOpenLogs_with_minimal_parameters() 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 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/GetLogs")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -216,12 +213,11 @@ public async Task GetRelayClickLogs_with_minimal_parameters() 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 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/GetLogs")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -236,12 +232,11 @@ public async Task GetRelayBounceLogs_with_minimal_parameters() 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 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/GetLogs")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -257,12 +252,11 @@ 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 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/GetLogs")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -278,12 +272,11 @@ 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 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/GetLogs")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -299,12 +292,11 @@ 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 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/GetLogs")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -320,12 +312,11 @@ 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 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/GetLogs")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -340,12 +331,11 @@ public async Task GetRelayLogs_with_offset() 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 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/GetLogs")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); diff --git a/Source/CakeMail.RestClient.UnitTests/Resources/Segments.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Segments.cs index 0f05f46..d8ff284 100644 --- a/Source/CakeMail.RestClient.UnitTests/Resources/Segments.cs +++ b/Source/CakeMail.RestClient.UnitTests/Resources/Segments.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; using Xunit; -namespace CakeMail.RestClient.UnitTests +namespace CakeMail.RestClient.UnitTests.Resources { public class SegmentsTests { @@ -23,7 +23,7 @@ public async Task CreateSegment_with_query() var segmentId = 456L; var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", segmentId); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/CreateSublist/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/CreateSublist")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -42,7 +42,7 @@ public async Task CreateSegment_with_clientid() var segmentId = 456L; var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", segmentId); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/CreateSublist/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/CreateSublist")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -61,7 +61,7 @@ public async Task UpdateSegment_name() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -80,7 +80,7 @@ public async Task UpdateSegment_query() var query = "???"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -98,7 +98,7 @@ public async Task UpdateSegment_clientid() var segmentId = 456L; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -115,7 +115,7 @@ public async Task DeleteSegment_wit_minimal_parameters() var segmentId = 456L; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/DeleteSublist/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/DeleteSublist")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -132,7 +132,7 @@ public async Task DeleteSegment_with_clientid() var segmentId = 456L; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/DeleteSublist/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/DeleteSublist")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -149,7 +149,7 @@ public async Task GetSegment_with_minimal_parameters() var segmentId = 456L; 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 mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -167,7 +167,7 @@ public async Task GetSegment_with_includestatistics_true() var segmentId = 456L; 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 mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -185,7 +185,7 @@ public async Task GetSegment_with_includestatistics_false() var segmentId = 456L; 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 mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -203,7 +203,7 @@ public async Task GetSegment_with_calculateengagement_true() var segmentId = 456L; 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 mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -221,7 +221,7 @@ public async Task GetSegment_with_calculateengagement_false() var segmentId = 456L; 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 mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -239,7 +239,7 @@ public async Task GetSegment_with_clientid() var segmentId = 456L; 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 mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -259,7 +259,7 @@ public async Task GetSegments_with_details_false() 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 jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"sublists\":[{0},{1}]}}}}", jsonSegment1, jsonSegment2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetSublists/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetSublists")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -280,7 +280,7 @@ public async Task GetSegments_with_limit() 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 jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"sublists\":[{0},{1}]}}}}", jsonSegment1, jsonSegment2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetSublists/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetSublists")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -301,7 +301,7 @@ public async Task GetSegments_with_offset() 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 jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"sublists\":[{0},{1}]}}}}", jsonSegment1, jsonSegment2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetSublists/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetSublists")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -321,7 +321,7 @@ public async Task GetSegments_with_clientid() 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 jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"sublists\":[{0},{1}]}}}}", jsonSegment1, jsonSegment2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetSublists/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetSublists")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -339,7 +339,7 @@ public async Task GetSegmentsCount_with_minimal_parameters() var listId = 123L; var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -356,7 +356,7 @@ public async Task GetSegmentsCount_with_clientid() var listId = 123L; var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/List/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); diff --git a/Source/CakeMail.RestClient.UnitTests/Resources/SuppressionLists.cs b/Source/CakeMail.RestClient.UnitTests/Resources/SuppressionLists.cs index 8dfe3a1..295cfd4 100644 --- a/Source/CakeMail.RestClient.UnitTests/Resources/SuppressionLists.cs +++ b/Source/CakeMail.RestClient.UnitTests/Resources/SuppressionLists.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; using Xunit; -namespace CakeMail.RestClient.UnitTests +namespace CakeMail.RestClient.UnitTests.Resources { public class SuppressionListsTests { @@ -20,7 +20,7 @@ public async Task AddEmailAddressesToSuppressionList_with_minimal_parameters() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ImportEmails")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -37,7 +37,7 @@ 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ImportEmails")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -55,7 +55,7 @@ public async Task AddEmailAddressesToSuppressionList_with_clientid() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ImportEmails")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -73,7 +73,7 @@ public async Task AddDomainsToSuppressionList_with_minimal_parameters() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ImportDomains")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -90,7 +90,7 @@ 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ImportDomains")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -108,7 +108,7 @@ public async Task AddDomainsToSuppressionList_with_clientid() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ImportDomains")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -124,9 +124,9 @@ public async Task AddLocalPartsToSuppressionList_with_minimal_parameters() { // Arrange var localParts = new[] { "administrator", "manager", "info" }; - var jsonResponse = "{\"status\":\"success\",\"data\":{\"localparts\":[{\"localpart\":\"administrator\"},{\"localpart\":\"manager\"},{\"localpart\":\"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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ImportLocalparts")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -141,9 +141,9 @@ public async Task AddLocalPartsToSuppressionList_with_minimal_parameters() public async Task AddLocalPartsToSuppressionList_with_null_array() { // Arrange - var jsonResponse = "{\"status\":\"success\",\"data\":{\"localparts\":[]}}"; + var jsonResponse = "{\"status\":\"success\",\"data\":[]}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/ImportLocalparts/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ImportLocalparts")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -159,9 +159,9 @@ public async Task AddLocalPartsToSuppressionList_with_clientid() { // Arrange var localParts = new[] { "administrator", "manager", "info" }; - var jsonResponse = "{\"status\":\"success\",\"data\":{\"localparts\":[{\"localpart\":\"administrator\"},{\"localpart\":\"manager\"},{\"localpart\":\"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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ImportLocalparts")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -179,7 +179,7 @@ public async Task RemoveEmailAddressesFromSuppressionList_with_minimal_parameter 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/DeleteEmails")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -196,7 +196,7 @@ 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/DeleteEmails")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -214,7 +214,7 @@ public async Task RemoveEmailAddressesFromSuppressionList_with_clientid() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/DeleteEmails")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -232,7 +232,7 @@ public async Task RemoveDomainsFromSuppressionList_with_minimal_parameters() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/DeleteDomains")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -249,7 +249,7 @@ 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/DeleteDomains")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -267,7 +267,7 @@ public async Task RemoveDomainsFromSuppressionList_with_clientid() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/DeleteDomains")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -283,9 +283,9 @@ public async Task RemoveLocalPartsFromSuppressionList_with_minimal_parameters() { // Arrange var localParts = new[] { "administrator", "manager", "info" }; - var jsonResponse = "{\"status\":\"success\",\"data\":{\"localparts\":[{\"localpart\":\"administrator\"},{\"localpart\":\"manager\"},{\"localpart\":\"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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/DeleteLocalparts")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -300,9 +300,9 @@ public async Task RemoveLocalPartsFromSuppressionList_with_minimal_parameters() public async Task RemoveLocalPartsFromSuppressionList_with_null_array() { // Arrange - var jsonResponse = "{\"status\":\"success\",\"data\":{\"localparts\":[]}}"; + var jsonResponse = "{\"status\":\"success\",\"data\":[]}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/SuppressionList/DeleteLocalparts/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/DeleteLocalparts")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -318,9 +318,9 @@ public async Task RemoveLocalPartsFromSuppressionList_with_clientid() { // Arrange var localParts = new[] { "administrator", "manager", "info" }; - var jsonResponse = "{\"status\":\"success\",\"data\":{\"localparts\":[{\"localpart\":\"administrator\"},{\"localpart\":\"manager\"},{\"localpart\":\"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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/DeleteLocalparts")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -337,7 +337,7 @@ 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportEmails")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -355,7 +355,7 @@ public async Task GetSuppressedEmailAddresses_with_limit() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportEmails")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -373,7 +373,7 @@ public async Task GetSuppressedEmailAddresses_with_offset() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportEmails")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -390,7 +390,7 @@ 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportEmails")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -407,7 +407,7 @@ 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportDomains")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -425,7 +425,7 @@ public async Task GetSuppressedDomains_with_limit() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportDomains")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -443,7 +443,7 @@ public async Task GetSuppressedDomains_with_offset() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportDomains")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -460,7 +460,7 @@ 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportDomains")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -477,7 +477,7 @@ 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportLocalparts")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -495,7 +495,7 @@ public async Task GetSuppressedLocalParts_with_limit() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportLocalparts")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -513,7 +513,7 @@ public async Task GetSuppressedLocalParts_with_offset() 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportLocalparts")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -530,7 +530,7 @@ 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportLocalparts")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -547,7 +547,7 @@ 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportEmails")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -563,7 +563,7 @@ 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportEmails")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -579,7 +579,7 @@ 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportDomains")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -595,7 +595,7 @@ 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportDomains")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -611,7 +611,7 @@ 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportLocalparts")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -627,7 +627,7 @@ 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportLocalparts")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); diff --git a/Source/CakeMail.RestClient.UnitTests/Resources/Templates.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Templates.cs index 66fa7ab..24c3fe9 100644 --- a/Source/CakeMail.RestClient.UnitTests/Resources/Templates.cs +++ b/Source/CakeMail.RestClient.UnitTests/Resources/Templates.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; using Xunit; -namespace CakeMail.RestClient.UnitTests +namespace CakeMail.RestClient.UnitTests.Resources { public class TemplatesTests { @@ -27,7 +27,7 @@ public async Task CreateTemplateCategory_with_minimal_parameters() }; var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\"}}}}", CATEGORY_ID); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/CreateCategory/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/CreateCategory")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -43,7 +43,7 @@ public async Task CreateTemplateCategory_with_no_labels() // Arrange var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\"}}}}", CATEGORY_ID); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/CreateCategory/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/CreateCategory")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -64,7 +64,7 @@ public async Task CreateTemplateCategory_with_isvisiblebydefault_false() }; var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\"}}}}", CATEGORY_ID); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/CreateCategory/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/CreateCategory")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -85,7 +85,7 @@ public async Task CreateTemplateCategory_with_templatescanbecopied_false() }; var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\"}}}}", CATEGORY_ID); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/CreateCategory/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/CreateCategory")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -106,7 +106,7 @@ public async Task CreateTemplateCategory_with_clientid() }; var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\"}}}}", CATEGORY_ID); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/CreateCategory/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/CreateCategory")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -122,7 +122,7 @@ public async Task DeleteTemplateCategory_with_minimal_parameters() // Arrange var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/DeleteCategory/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/DeleteCategory")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -138,7 +138,7 @@ public async Task DeleteTemplateCategory_with_clientid() // Arrange var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/DeleteCategory/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/DeleteCategory")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -154,7 +154,7 @@ public async Task GetTemplateCategory_with_minimal_parameters() // Arrange 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 mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/GetCategory/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetCategory")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -171,7 +171,7 @@ public async Task GetTemplateCategory_with_clientid() // Arrange 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 mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/GetCategory/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetCategory")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -190,7 +190,7 @@ public async Task GetTemplateCategories_with_minimal_parameters() 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 jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"categories\":[{0},{1}]}}}}", jsonCategory1, jsonCategory2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/GetCategories/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetCategories")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -212,7 +212,7 @@ public async Task GetTemplateCategories_with_limit() 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 jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"categories\":[{0},{1}]}}}}", jsonCategory1, jsonCategory2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/GetCategories/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetCategories")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -234,7 +234,7 @@ public async Task GetTemplateCategories_with_offset() 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 jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"categories\":[{0},{1}]}}}}", jsonCategory1, jsonCategory2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/GetCategories/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetCategories")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -255,7 +255,7 @@ public async Task GetTemplateCategories_with_clientid() 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 jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"categories\":[{0},{1}]}}}}", jsonCategory1, jsonCategory2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/GetCategories/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetCategories")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -274,7 +274,7 @@ public async Task GetTemplateCategoriesCount_with_minimal_parameters() // Arrange var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/GetCategories/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetCategories")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -290,7 +290,7 @@ public async Task GetTemplateCategoriesCount_with_clientid() // Arrange var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/GetCategories/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetCategories")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -306,7 +306,7 @@ public async Task UpdateTemplateCategory_with_minimal_parameters() // Arrange var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/SetCategory/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/SetCategory")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -327,7 +327,7 @@ public async Task UpdateTemplateCategory_with_labels() }; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/SetCategory/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/SetCategory")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -343,7 +343,7 @@ public async Task UpdateTemplateCategory_with_default_true() // Arrange var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/SetCategory/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/SetCategory")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -359,7 +359,7 @@ public async Task UpdateTemplateCategory_with_default_false() // Arrange var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/SetCategory/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/SetCategory")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -375,7 +375,7 @@ public async Task UpdateTemplateCategory_with_copyable_true() // Arrange var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/SetCategory/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/SetCategory")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -391,7 +391,7 @@ public async Task UpdateTemplateCategory_with_copyable_false() // Arrange var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/SetCategory/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/SetCategory")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -407,7 +407,7 @@ public async Task UpdateTemplateCategory_with_clientid() // Arrange var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/SetCategory/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/SetCategory")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -425,7 +425,7 @@ public async Task GetTemplateCategoryVisibility_with_minimal_parameters() var jsonVisibility2 = "{\"client_id\":\"111\",\"company_name\":\"Fictitious Company #2\",\"visible\":\"0\"}"; var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"clients\":[{0},{1}]}}}}", jsonVisibility1, jsonVisibility2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/GetCategoryVisibility/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetCategoryVisibility")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -447,7 +447,7 @@ public async Task GetTemplateCategoryVisibility_with_limit() var jsonVisibility2 = "{\"client_id\":\"111\",\"company_name\":\"Fictitious Company #2\",\"visible\":\"0\"}"; var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"clients\":[{0},{1}]}}}}", jsonVisibility1, jsonVisibility2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/GetCategoryVisibility/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetCategoryVisibility")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -467,7 +467,7 @@ public async Task GetTemplateCategoryVisibility_with_offset() var jsonVisibility2 = "{\"client_id\":\"111\",\"company_name\":\"Fictitious Company #2\",\"visible\":\"0\"}"; var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"clients\":[{0},{1}]}}}}", jsonVisibility1, jsonVisibility2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/GetCategoryVisibility/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetCategoryVisibility")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -486,7 +486,7 @@ public async Task GetTemplateCategoryVisibility_with_clientid() var jsonVisibility2 = "{\"client_id\":\"111\",\"company_name\":\"Fictitious Company #2\",\"visible\":\"0\"}"; var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"clients\":[{0},{1}]}}}}", jsonVisibility1, jsonVisibility2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/GetCategoryVisibility/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetCategoryVisibility")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -503,7 +503,7 @@ public async Task GetTemplateCategoryVisibilityCount_with_minimal_parameters() // Arrange var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/GetCategoryVisibility/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetCategoryVisibility")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -519,7 +519,7 @@ public async Task GetTemplateCategoryVisibilityCount_with_clientid() // Arrange var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/GetCategoryVisibility/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetCategoryVisibility")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -540,7 +540,7 @@ public async Task SetTemplateCategoryVisibility_with_minimal_parameters() }; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/SetCategoryVisibility/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/SetCategoryVisibility")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -557,7 +557,7 @@ public async Task SetTemplateCategoryVisibility_with_empty_array() var clientVisibility = (IDictionary)null; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/SetCategoryVisibility/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/SetCategoryVisibility")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -578,7 +578,7 @@ public async Task SetTemplateCategoryVisibility_with_clientid() }; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/SetCategoryVisibility/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/SetCategoryVisibility")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -598,9 +598,9 @@ public async Task CreateTemplate_with_minimal_parameters() { "en_US", "My Template" }, { "fr_FR", "Mon Modèle" } }; - var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", TEMPLATE_ID); + 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/CreateTemplate")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -620,9 +620,9 @@ public async Task CreateTemplate_with_no_labels() { "en_US", "My Template" }, { "fr_FR", "Mon modèle" } }; - var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", TEMPLATE_ID); + 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/CreateTemplate")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -642,9 +642,9 @@ public async Task CreateTemplate_with_clientid() { "en_US", "My Template" }, { "fr_FR", "Mon Modèle" } }; - var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", TEMPLATE_ID); + 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/CreateTemplate")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -660,7 +660,7 @@ public async Task DeleteTemplate_with_minimal_parameters() // Arrange var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/DeleteTemplate/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/DeleteTemplate")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -676,7 +676,7 @@ public async Task DeleteTemplate_with_clientid() // Arrange var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/DeleteTemplate/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/DeleteTemplate")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -692,7 +692,7 @@ public async Task GetTemplate_with_minimal_parameters() // Arrange 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 mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/GetTemplate/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetTemplate")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -709,7 +709,7 @@ public async Task GetTemplate_with_clientid() // Arrange 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 mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/GetTemplate/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetTemplate")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -728,7 +728,7 @@ public async Task GetTemplates_with_minimal_parameters() 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 jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"templates\":[{0},{1}]}}}}", jsonTemplate1, jsonTemplate2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/GetTemplates/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetTemplates")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -749,7 +749,7 @@ public async Task GetTemplates_with_CATEGORY_ID() 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 jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"templates\":[{0},{1}]}}}}", jsonTemplate1, jsonTemplate2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/GetTemplates/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetTemplates")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -771,7 +771,7 @@ public async Task GetTemplates_with_limit() 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 jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"templates\":[{0},{1}]}}}}", jsonTemplate1, jsonTemplate2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/GetTemplates/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetTemplates")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -793,7 +793,7 @@ public async Task GetTemplates_with_offset() 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 jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"templates\":[{0},{1}]}}}}", jsonTemplate1, jsonTemplate2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/GetTemplates/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetTemplates")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -814,7 +814,7 @@ public async Task GetTemplates_with_clientid() 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 jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"templates\":[{0},{1}]}}}}", jsonTemplate1, jsonTemplate2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/GetTemplates/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetTemplates")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -833,7 +833,7 @@ public async Task GetTemplatesCount_with_minimal_parameters() // Arrange var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/GetTemplates/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetTemplates")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -849,7 +849,7 @@ public async Task GetTemplatesCount_with_CATEGORY_ID() // Arrange var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/GetTemplates/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetTemplates")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -865,7 +865,7 @@ public async Task GetTemplatesCount_with_clientid() // Arrange var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/GetTemplates/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetTemplates")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -881,7 +881,7 @@ public async Task UpdateTemplate_with_minimal_parameters() // Arrange var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/SetTemplate/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/SetTemplate")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -902,7 +902,7 @@ public async Task UpdateTemplate_with_labels() }; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/SetTemplate/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/SetTemplate")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -919,7 +919,7 @@ public async Task UpdateTemplate_with_content() var content = "Sample content 4"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/SetTemplate/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/SetTemplate")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -935,7 +935,7 @@ public async Task UpdateTemplate_with_CATEGORY_ID() // Arrange var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/SetTemplate/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/SetTemplate")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -951,7 +951,7 @@ public async Task UpdateTemplate_with_clientid() // Arrange var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/TemplateV2/SetTemplate/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/SetTemplate")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); diff --git a/Source/CakeMail.RestClient.UnitTests/Resources/Timezones.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Timezones.cs index 958a4ab..b9cac8e 100644 --- a/Source/CakeMail.RestClient.UnitTests/Resources/Timezones.cs +++ b/Source/CakeMail.RestClient.UnitTests/Resources/Timezones.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; using Xunit; -namespace CakeMail.RestClient.UnitTests +namespace CakeMail.RestClient.UnitTests.Resources { public class TimezonesTests { @@ -18,7 +18,7 @@ public async Task GetTimezones() var jsonResponse = "{\"status\":\"success\",\"data\":{\"timezones\":[{\"id\":\"152\",\"name\":\"America/Montreal\"},{\"id\":\"532\",\"name\":\"US/Central\"},{\"id\":\"542\",\"name\":\"UTC\"}]}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Client/GetTimezones")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/GetTimezones")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); diff --git a/Source/CakeMail.RestClient.UnitTests/Resources/Triggers.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Triggers.cs index f13c3b8..a9414b1 100644 --- a/Source/CakeMail.RestClient.UnitTests/Resources/Triggers.cs +++ b/Source/CakeMail.RestClient.UnitTests/Resources/Triggers.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; using Xunit; -namespace CakeMail.RestClient.UnitTests +namespace CakeMail.RestClient.UnitTests.Resources { public class TriggersTests { @@ -25,7 +25,7 @@ public async Task CreateTrigger_with_minimal_parameters() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", triggerId); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/Create/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/Create")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -46,7 +46,7 @@ public async Task CreateTrigger_with_campaignid() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", triggerId); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/Create/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/Create")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -67,7 +67,7 @@ public async Task CreateTrigger_with_encoding() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", triggerId); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/Create/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/Create")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -88,7 +88,7 @@ public async Task CreateTrigger_with_transferencoding() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", triggerId); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/Create/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/Create")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -108,7 +108,7 @@ public async Task CreateTrigger_with_clientid() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", triggerId); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/Create/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/Create")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -126,7 +126,7 @@ public async Task GetTrigger_with_minimal_parameters() 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 mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -145,7 +145,7 @@ public async Task GetTrigger_with_clientid() 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 mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -164,7 +164,7 @@ public async Task UpdateTrigger_with_minimal_parameters() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -183,7 +183,7 @@ public async Task UpdateTrigger_with_campaignid() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -202,7 +202,7 @@ public async Task UpdateTrigger_with_name() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -221,7 +221,7 @@ public async Task UpdateTrigger_with_action() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -240,7 +240,7 @@ public async Task UpdateTrigger_with_encoding() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -259,7 +259,7 @@ public async Task UpdateTrigger_with_transferencoding() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -278,7 +278,7 @@ public async Task UpdateTrigger_with_subject() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -297,7 +297,7 @@ public async Task UpdateTrigger_with_senderemail() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -316,7 +316,7 @@ public async Task UpdateTrigger_with_sendername() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -335,7 +335,7 @@ public async Task UpdateTrigger_with_replyto() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -354,7 +354,7 @@ public async Task UpdateTrigger_with_htmlcontent() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -373,7 +373,7 @@ public async Task UpdateTrigger_with_textcontent() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -391,7 +391,7 @@ public async Task UpdateTrigger_with_trackopens_true() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -409,7 +409,7 @@ public async Task UpdateTrigger_with_trackopens_false() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -427,7 +427,7 @@ public async Task UpdateTrigger_with_trackclicksinhtml_true() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -445,7 +445,7 @@ public async Task UpdateTrigger_with_trackclicksinhtml_false() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -463,7 +463,7 @@ public async Task UpdateTrigger_with_trackclicksintext_true() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -481,7 +481,7 @@ public async Task UpdateTrigger_with_trackclicksintext_false() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -500,7 +500,7 @@ public async Task UpdateTrigger_with_trackingparameters() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -519,7 +519,7 @@ public async Task UpdateTrigger_with_delay() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -538,7 +538,7 @@ public async Task UpdateTrigger_with_status() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -557,7 +557,7 @@ public async Task UpdateTrigger_with_datefield() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -575,7 +575,7 @@ public async Task UpdateTrigger_with_clientid() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -594,7 +594,7 @@ public async Task GetTriggers_with_minimal_parameters() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"triggers\":[{0},{1}]}}}}", jsonTrigger1, jsonTrigger2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -617,7 +617,7 @@ public async Task GetTriggers_with_status() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"triggers\":[{0},{1}]}}}}", jsonTrigger1, jsonTrigger2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -640,7 +640,7 @@ public async Task GetTriggers_with_action() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"triggers\":[{0},{1}]}}}}", jsonTrigger1, jsonTrigger2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -663,7 +663,7 @@ public async Task GetTriggers_with_listid() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"triggers\":[{0},{1}]}}}}", jsonTrigger1, jsonTrigger2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -686,7 +686,7 @@ public async Task GetTriggers_with_campaignid() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"triggers\":[{0},{1}]}}}}", jsonTrigger1, jsonTrigger2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -709,7 +709,7 @@ public async Task GetTriggers_with_limit() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"triggers\":[{0},{1}]}}}}", jsonTrigger1, jsonTrigger2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -732,7 +732,7 @@ public async Task GetTriggers_with_offset() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"triggers\":[{0},{1}]}}}}", jsonTrigger1, jsonTrigger2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -754,7 +754,7 @@ public async Task GetTriggers_with_clientid() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"triggers\":[{0},{1}]}}}}", jsonTrigger1, jsonTrigger2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -773,7 +773,7 @@ public async Task GetTriggersCount_with_minimal_parameters() // Arrange var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -791,7 +791,7 @@ public async Task GetTriggersCount_with_status() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -809,7 +809,7 @@ public async Task GetTriggersCount_with_action() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -827,7 +827,7 @@ public async Task GetTriggersCount_with_listid() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -845,7 +845,7 @@ public async Task GetTriggersCount_with_campaignid() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -861,7 +861,7 @@ public async Task GetTriggersCount_with_clientid() // Arrange var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -880,7 +880,7 @@ public async Task SendTriggerTestEmail_with_minimal_parameters() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/SendTestEmail/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SendTestEmail")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -899,7 +899,7 @@ public async Task SendTriggerTestEmail_with_separated_true() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/SendTestEmail/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SendTestEmail")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -918,7 +918,7 @@ public async Task SendTriggerTestEmail_with_clientid() var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/SendTestEmail/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SendTestEmail")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -936,7 +936,7 @@ public async Task GetTriggerRawEmailMessage_with_minimal_parameters() var jsonResponse = "{\"status\":\"success\",\"data\":{\"subject\":\"This is a simple message\",\"message\":\"...dummy content...\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetEmailMessage/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetEmailMessage")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -955,7 +955,7 @@ public async Task GetTriggerRawEmailMessage_with_clientid() var jsonResponse = "{\"status\":\"success\",\"data\":{\"subject\":\"This is a simple message\",\"message\":\"...dummy content...\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetEmailMessage/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetEmailMessage")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -974,7 +974,7 @@ public async Task GetTriggerRawHtml_with_minimal_parameters() var jsonResponse = "{\"status\":\"success\",\"data\":\"...dummy content...\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetHtmlMessage/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetHtmlMessage")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -992,7 +992,7 @@ public async Task GetTriggerRawHtml_with_clientid() var jsonResponse = "{\"status\":\"success\",\"data\":\"...dummy content...\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetHtmlMessage/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetHtmlMessage")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1010,7 +1010,7 @@ public async Task GetTriggerRawText_with_minimal_parameters() var jsonResponse = "{\"status\":\"success\",\"data\":\"...dummy content...\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetTextMessage/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetTextMessage")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1028,7 +1028,7 @@ public async Task GetTriggerRawText_with_clientid() var jsonResponse = "{\"status\":\"success\",\"data\":\"...dummy content...\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetTextMessage/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetTextMessage")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1046,7 +1046,7 @@ public async Task UnleashTrigger_with_minimal_parameters() var listMemberId = 111L; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/Unleash/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/Unleash")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1064,7 +1064,7 @@ public async Task UnleashTrigger_with_clientid() var listMemberId = 111L; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/Unleash/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/Unleash")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1085,7 +1085,7 @@ public async Task GetTriggerLogs_with_minimal_parameters() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1107,7 +1107,7 @@ public async Task GetTriggerLogs_with_logtype() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0}]}}}}", sentLog); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1129,7 +1129,7 @@ public async Task GetTriggerLogs_with_listmemberid() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0}]}}}}", sentLog); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1152,7 +1152,7 @@ public async Task GetTriggerLogs_with_startdate() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1175,7 +1175,7 @@ public async Task GetTriggerLogs_with_enddate() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1198,7 +1198,7 @@ public async Task GetTriggerLogs_with_limit() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1221,7 +1221,7 @@ public async Task GetTriggerLogs_with_offset() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1243,7 +1243,7 @@ public async Task GetTriggerLogs_with_clientid() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1265,7 +1265,7 @@ public async Task GetTriggerLogs_with_uniques_true() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1287,7 +1287,7 @@ public async Task GetTriggerLogs_with_totals_true() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1306,7 +1306,7 @@ public async Task GetTriggerLogsCount_with_minimal_parameters() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1326,7 +1326,7 @@ public async Task GetTriggerLogsCount_with_logtype() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1346,7 +1346,7 @@ public async Task GetTriggerLogsCount_with_listmemberid() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1365,7 +1365,7 @@ public async Task GetTriggerLogsCount_with_uniques_true() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1384,7 +1384,7 @@ public async Task GetTriggerLogsCount_with_totals_true() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1404,7 +1404,7 @@ public async Task GetTriggerLogsCount_with_startdate() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1424,7 +1424,7 @@ public async Task GetTriggerLogsCount_with_enddate() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1443,7 +1443,7 @@ public async Task GetTriggerLogsCount_with_clientid() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1465,7 +1465,7 @@ public async Task GetTriggerLinks_with_minimal_parameters() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonLink1, jsonLink2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLinks/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinks")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1488,7 +1488,7 @@ public async Task GetTriggerLinks_with_limit() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonLink1, jsonLink2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLinks/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinks")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1511,7 +1511,7 @@ public async Task GetTriggerLinks_with_offset() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonLink1, jsonLink2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLinks/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinks")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1533,7 +1533,7 @@ public async Task GetTriggerLinks_with_clientid() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonLink1, jsonLink2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLinks/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinks")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1552,7 +1552,7 @@ public async Task GetTriggerLinksCount_with_minimal_parameters() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLinks/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinks")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1570,7 +1570,7 @@ public async Task GetTriggerLinksCount_with_clientid() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLinks/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinks")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1588,7 +1588,7 @@ public async Task GetTriggerLink_with_minimal_parameters() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"status\":\"active\",\"link_to\":\"http://www.fictitiouscompany.com.com/\"}}}}", linkId); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLinkInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinkInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1607,7 +1607,7 @@ public async Task GetTriggerLink_with_clientid() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"status\":\"active\",\"link_to\":\"http://www.fictitiouscompany.com.com/\"}}}}", linkId); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLinkInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinkInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1629,7 +1629,7 @@ public async Task GetTriggerLinksWithStats_with_minimal_parameters() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonClickLog1, jsonClickLog2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLinksLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinksLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1652,7 +1652,7 @@ public async Task GetTriggerLinksWithStats_with_startdate() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonClickLog1, jsonClickLog2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLinksLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinksLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1675,7 +1675,7 @@ public async Task GetTriggerLinksWithStats_with_enddate() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonClickLog1, jsonClickLog2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLinksLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinksLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1698,7 +1698,7 @@ public async Task GetTriggerLinksWithStats_with_limit() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonClickLog1, jsonClickLog2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLinksLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinksLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1721,7 +1721,7 @@ public async Task GetTriggerLinksWithStats_with_offset() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonClickLog1, jsonClickLog2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLinksLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinksLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1743,7 +1743,7 @@ public async Task GetTriggerLinksWithStats_with_clientid() var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonClickLog1, jsonClickLog2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLinksLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinksLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1762,7 +1762,7 @@ public async Task GetTriggerLinksWithStatsCount_with_minimal_parameters() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLinksLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinksLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1782,7 +1782,7 @@ public async Task GetTriggerLinksWithStatsCount_with_startdate() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLinksLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinksLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1802,7 +1802,7 @@ public async Task GetTriggerLinksWithStatsCount_with_enddate() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLinksLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinksLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -1821,7 +1821,7 @@ public async Task GetTriggerLinksWithStatsCount_with_clientid() var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/Trigger/GetLinksLog/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinksLog")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); diff --git a/Source/CakeMail.RestClient.UnitTests/Resources/Users.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Users.cs index d8e3deb..48ac210 100644 --- a/Source/CakeMail.RestClient.UnitTests/Resources/Users.cs +++ b/Source/CakeMail.RestClient.UnitTests/Resources/Users.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; using Xunit; -namespace CakeMail.RestClient.UnitTests +namespace CakeMail.RestClient.UnitTests.Resources { public class UsersTests { @@ -21,10 +21,9 @@ public async Task CreateUser_with_minimal_parameters() var userId = 123L; var email = "bob@fictitiouscompany.com"; var password = "MyPassword"; - var timezoneId = 542L; - var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", userId); + 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); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/Create")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -42,10 +41,9 @@ public async Task CreateUser_with_firstname() var email = "bob@fictitiouscompany.com"; var password = "MyPassword"; var firstName = "Bob"; - var timezoneId = 542L; var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"key\":\"...user key...\"}}}}", userId); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/Create/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/Create")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -63,10 +61,9 @@ public async Task CreateUser_with_lastname() var email = "bob@fictitiouscompany.com"; var password = "MyPassword"; var lastName = "Smith"; - var timezoneId = 542L; var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"key\":\"...user key...\"}}}}", userId); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/Create/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/Create")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -84,10 +81,9 @@ public async Task CreateUser_with_title() var email = "bob@fictitiouscompany.com"; var password = "MyPassword"; var title = "Marketing Director"; - var timezoneId = 542L; var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"key\":\"...user key...\"}}}}", userId); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/Create/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/Create")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -105,10 +101,9 @@ public async Task CreateUser_with_officephone() var email = "bob@fictitiouscompany.com"; var password = "MyPassword"; var officePhone = "555-555-1212"; - var timezoneId = 542L; var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"key\":\"...user key...\"}}}}", userId); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/Create/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/Create")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -126,10 +121,9 @@ public async Task CreateUser_with_mobilephone() var email = "bob@fictitiouscompany.com"; var password = "MyPassword"; var mobilePhone = "555-111-2222"; - var timezoneId = 542L; var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"key\":\"...user key...\"}}}}", userId); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/Create/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/Create")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -147,10 +141,9 @@ public async Task CreateUser_with_language() var email = "bob@fictitiouscompany.com"; var password = "MyPassword"; var language = "en-US"; - var timezoneId = 542L; var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"key\":\"...user key...\"}}}}", userId); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/Create/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/Create")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -170,7 +163,7 @@ public async Task CreateUser_with_timezoneid() var timezoneId = 542L; var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"key\":\"...user key...\"}}}}", userId); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/Create/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/Create")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -187,10 +180,9 @@ public async Task CreateUser_with_clientid() var userId = 123L; var email = "bob@fictitiouscompany.com"; var password = "MyPassword"; - var timezoneId = 542L; var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"key\":\"...user key...\"}}}}", userId); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/Create/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/Create")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -207,7 +199,7 @@ public async Task DeactivateUser_with_minimal_parameters() var userId = 12345L; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -224,7 +216,7 @@ public async Task DeleteUser_with_minimal_parameters() var userId = 12345L; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -241,7 +233,7 @@ public async Task GetUser_with_minimal_parameters() var userId = 12345L; 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 mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/GetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/GetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -259,7 +251,7 @@ public async Task GetUser_with_clientid() var userId = 12345L; 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 mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/GetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/GetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -278,7 +270,7 @@ public async Task GetUsers_with_minimal_parameters() 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 jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"users\":[{0},{1}]}}}}", jsonUser1, jsonUser2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -300,7 +292,7 @@ public async Task GetUsers_with_status() 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 jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"users\":[{0},{1}]}}}}", jsonUser1, jsonUser2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -322,7 +314,7 @@ public async Task GetUsers_with_limit() 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 jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"users\":[{0},{1}]}}}}", jsonUser1, jsonUser2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -344,7 +336,7 @@ public async Task GetUsers_with_offset() 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 jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"users\":[{0},{1}]}}}}", jsonUser1, jsonUser2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -365,7 +357,7 @@ public async Task GetUsers_with_clientid() 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 jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"users\":[{0},{1}]}}}}", jsonUser1, jsonUser2); var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -384,7 +376,7 @@ public async Task GetUsersCount_with_minimal_parameters() // Arrange var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -401,7 +393,7 @@ public async Task GetUsersCount_with_status() var status = UserStatus.Active; var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -417,7 +409,7 @@ public async Task GetUsersCount_with_clientid() // Arrange var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/GetList/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/GetList")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -434,7 +426,7 @@ public async Task UpdateUser_with_minimal_parameters() var userId = 123L; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -452,7 +444,7 @@ public async Task UpdateUser_with_email() var email = "bob@fictitiouscompany.com"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -470,7 +462,7 @@ public async Task UpdateUser_with_password() var password = "AbCdEfGhIjKlMnOpQrStUvWxYz"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -488,7 +480,7 @@ public async Task UpdateUser_with_firstname() var firstName = "Bob"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -506,7 +498,7 @@ public async Task UpdateUser_with_lastname() var lastName = "Smith"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -524,7 +516,7 @@ public async Task UpdateUser_with_title() var title = "Marketing Director"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -542,7 +534,7 @@ public async Task UpdateUser_with_officephone() var officePhone = "555-555-1212"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -560,7 +552,7 @@ public async Task UpdateUser_with_mobilephone() var mobilePhone = "555-111-2222"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -578,7 +570,7 @@ public async Task UpdateUser_with_language() var language = "en-US"; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -596,7 +588,7 @@ public async Task UpdateUser_with_timezoneid() var timezoneId = 542L; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -614,7 +606,7 @@ public async Task UpdateUser_with_status() var status = UserStatus.Active; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -631,7 +623,7 @@ public async Task UpdateUser_with_clientid() var userId = 123L; var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}"; var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/SetInfo/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/SetInfo")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -649,7 +641,7 @@ public async Task Login_with_minimal_parameters() var password = "abc123"; 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 mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/Login/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/Login")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); @@ -668,7 +660,7 @@ public async Task Login_with_clientid() var password = "abc123"; 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 mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("/User/Login/")).Respond("application/json", jsonResponse); + mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/Login")).Respond("application/json", jsonResponse); // Act var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient()); diff --git a/Source/CakeMail.RestClient.UnitTests/project.json b/Source/CakeMail.RestClient.UnitTests/project.json index 7cb7808..d6da276 100644 --- a/Source/CakeMail.RestClient.UnitTests/project.json +++ b/Source/CakeMail.RestClient.UnitTests/project.json @@ -26,7 +26,7 @@ "dependencies": { "Microsoft.NETCore.App": { "type": "platform", - "version": "1.0.1" + "version": "1.1.0" } } }, diff --git a/Source/CakeMail.RestClient/CakeMailRestClient.cs b/Source/CakeMail.RestClient/CakeMailRestClient.cs index d28d3bd..5aedf0b 100644 --- a/Source/CakeMail.RestClient/CakeMailRestClient.cs +++ b/Source/CakeMail.RestClient/CakeMailRestClient.cs @@ -1,19 +1,11 @@ -using CakeMail.RestClient.Exceptions; -using CakeMail.RestClient.Resources; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; +using CakeMail.RestClient.Resources; +using CakeMail.RestClient.Utilities; +using Pathoschild.Http.Client; +using Pathoschild.Http.Client.Extensibility; using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; using System.Net; using System.Net.Http; -using System.Net.Http.Headers; using System.Reflection; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using CakeMail.RestClient.Utilities; namespace CakeMail.RestClient { @@ -24,14 +16,12 @@ public class CakeMailRestClient : ICakeMailRestClient { #region FIELDS + private const string DEFAULT_HOST = "api.wbsrvc.com"; + private readonly bool _mustDisposeHttpClient; private HttpClient _httpClient; - - private enum Methods - { - GET, PUT, POST, PATCH, DELETE - } + private Pathoschild.Http.Client.IClient _fluentClient; #endregion @@ -47,11 +37,6 @@ private enum Methods /// public string UserAgent { get; private set; } - /// - /// The timeout - /// - public int Timeout { get; private set; } - /// /// The URL where all API requests are sent /// @@ -156,39 +141,39 @@ public CakeMailRestClient(string apiKey, IWebProxy proxy) /// /// 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. /// 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 = "api.wbsrvc.com", int timeout = 5000, HttpClient httpClient = null) + public CakeMailRestClient(string apiKey, string host = DEFAULT_HOST, HttpClient httpClient = null) { + _mustDisposeHttpClient = httpClient == null; + _httpClient = httpClient; + ApiKey = apiKey; BaseUrl = new Uri($"https://{host.TrimEnd('/')}/"); - Timeout = timeout; - Version = typeof(CakeMailRestClient).GetTypeInfo().Assembly.GetName().Version.ToString(); UserAgent = $"CakeMail .NET REST Client/{Version} (+https://github.com/Jericho/CakeMail.RestClient)"; - Campaigns = new Campaigns(this); - Clients = new Clients(this); - Countries = new Countries(this); - Permissions = new Permissions(this); - Lists = new Lists(this); - Timezones = new Timezones(this); - Mailings = new Mailings(this); - Relays = new Relays(this); - Segments = new Segments(this); - Users = new Users(this); - SuppressionLists = new SuppressionLists(this); - Templates = new Templates(this); - Triggers = new Triggers(this); - - _mustDisposeHttpClient = httpClient == null; - _httpClient = httpClient ?? new HttpClient(); - _httpClient.Timeout = TimeSpan.FromMilliseconds(Timeout); - _httpClient.BaseAddress = BaseUrl; - _httpClient.DefaultRequestHeaders.Accept.Clear(); - _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - _httpClient.DefaultRequestHeaders.Add("apikey", ApiKey); - _httpClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", UserAgent); + _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); } /// @@ -239,158 +224,16 @@ protected virtual void Dispose(bool disposing) #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); - - // Make sure response indicates success - response.EnsureSuccess(); - - // Parse the response - var data = await ParseCakeMailResponseAsync(response).ConfigureAwait(false); - - // Check if the response is a well-known object type (JArray or 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 endpoint, IEnumerable> parameters, CancellationToken cancellationToken = default(CancellationToken)) - { - var content = (StringContent)null; - if (parameters != null) - { - var paramsWithValue = parameters.Where(p => p.Value != null).Select(p => string.Concat(Uri.EscapeDataString(p.Key), "=", Uri.EscapeDataString(p.Value.ToString()))); - var paramsWithoutValue = parameters.Where(p => p.Value == null).Select(p => string.Concat(Uri.EscapeDataString(p.Key), "=")); - var allParams = paramsWithValue.Union(paramsWithoutValue).ToArray(); - content = new StringContent(string.Join("&", allParams), Encoding.UTF8, "application/x-www-form-urlencoded"); - } - - var response = await RequestAsync(Methods.POST, endpoint, content, cancellationToken).ConfigureAwait(false); - -#if DEBUG - var debugRequestMsg = string.Format("Request sent to CakeMail: {0}/{1}", BaseUrl.ToString().TrimEnd('/'), endpoint.TrimStart('/')); - var debugParametersMsg = string.Format("Request parameters: {0}", parameters == null ? "[NULL]" : string.Join("&", parameters.Select(p => string.Concat(p.Key, "=", p.Value)))); - var debugResponseMsg = string.Format("Response received: {0}", response.Content == null ? "[NULL]" : await response.Content.ReadAsStringAsync().ConfigureAwait(false)); - Debug.WriteLine("{0}\r\n{1}\r\n{2}\r\n{3}\r\n{0}", new string('=', 25), debugRequestMsg, debugParametersMsg, debugResponseMsg); -#endif - - return response; - } - - #endregion - #region PRIVATE METHODS - /// - /// Create a client that connects to the SendGrid Web API - /// - /// HTTP verb, case-insensitive - /// Resource endpoint - /// A StringContent representing the content of the http request - /// An asyncronous task - private async Task RequestAsync(Methods method, string endpoint, StringContent content, CancellationToken cancellationToken = default(CancellationToken)) - { - try - { - var methodAsString = string.Empty; - switch (method) - { - case Methods.GET: methodAsString = "GET"; break; - case Methods.PUT: methodAsString = "PUT"; break; - case Methods.POST: methodAsString = "POST"; break; - case Methods.PATCH: methodAsString = "PATCH"; break; - case Methods.DELETE: methodAsString = "DELETE"; break; - default: - var message = "{\"errors\":[{\"message\":\"Bad method call, supported methods are GET, PUT, POST, PATCH and DELETE\"}]}"; - return new HttpResponseMessage(HttpStatusCode.MethodNotAllowed) - { - Content = new StringContent(message) - }; - } - - var httpRequest = new HttpRequestMessage - { - Method = new HttpMethod(methodAsString), - RequestUri = new Uri(BaseUrl, endpoint.TrimStart('/')), - Content = content - }; - var response = await _httpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); - return response; - } - catch (Exception ex) - { - var message = string.Format(".NET {0}, raw message: \n\n{1}", (ex is HttpRequestException) ? "HttpRequestException" : "Exception", ex.GetBaseException().Message); - return new HttpResponseMessage(HttpStatusCode.BadRequest) - { - Content = new StringContent(message) - }; - } - } - - private async Task ParseCakeMailResponseAsync(HttpResponseMessage response) + private void ReleaseManagedResources() { - 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 responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var cakeResponse = JObject.Parse(responseContent); - 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) + if (_fluentClient != null) { - throw new CakeMailException(string.Format("Unable to decode response from CakeMail as JSON: {0}", response.Content), ex); + _fluentClient.Dispose(); + _fluentClient = null; } - } - private void ReleaseManagedResources() - { if (_httpClient != null && _mustDisposeHttpClient) { _httpClient.Dispose(); diff --git a/Source/CakeMail.RestClient/Exceptions/HttpException.cs b/Source/CakeMail.RestClient/Exceptions/HttpException.cs index 7cc9fd0..347744a 100644 --- a/Source/CakeMail.RestClient/Exceptions/HttpException.cs +++ b/Source/CakeMail.RestClient/Exceptions/HttpException.cs @@ -11,12 +11,12 @@ namespace CakeMail.RestClient.Exceptions 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; } diff --git a/Source/CakeMail.RestClient/ICakeMailRestClient.cs b/Source/CakeMail.RestClient/ICakeMailRestClient.cs index 0b47de5..6cb2d29 100644 --- a/Source/CakeMail.RestClient/ICakeMailRestClient.cs +++ b/Source/CakeMail.RestClient/ICakeMailRestClient.cs @@ -9,37 +9,44 @@ namespace CakeMail.RestClient public interface ICakeMailRestClient { /// - /// The API key provided by CakeMail + /// Gets the API key provided by CakeMail /// string ApiKey { 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; } } } diff --git a/Source/CakeMail.RestClient/Resources/Campaigns.cs b/Source/CakeMail.RestClient/Resources/Campaigns.cs index dd473f4..f5d13a6 100644 --- a/Source/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,7 +12,7 @@ public class Campaigns { #region Fields - private readonly CakeMailRestClient _cakeMailRestClient; + private readonly IClient _client; #endregion @@ -19,10 +21,10 @@ public class Campaigns /// /// Initializes a new instance of the class. /// - /// The HTTP client - public Campaigns(CakeMailRestClient cakeMailRestClient) + /// The HTTP client + public Campaigns(IClient client) { - _cakeMailRestClient = cakeMailRestClient; + _client = client; } #endregion @@ -39,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), @@ -48,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(); } /// @@ -61,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), @@ -70,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(); } /// @@ -83,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), @@ -92,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(); } /// @@ -107,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), @@ -125,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"); } /// @@ -139,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), @@ -149,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"); } /// @@ -163,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), @@ -173,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/Source/CakeMail.RestClient/Resources/Clients.cs b/Source/CakeMail.RestClient/Resources/Clients.cs index 60a1fcb..9b36596 100644 --- a/Source/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), @@ -116,7 +119,11 @@ public Task CreateAsync(long parentId, string name, string address1 = nu } } - 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/Source/CakeMail.RestClient/Resources/Countries.cs b/Source/CakeMail.RestClient/Resources/Countries.cs index b0ac82c..8b2eef8 100644 --- a/Source/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/Source/CakeMail.RestClient/Resources/Lists.cs b/Source/CakeMail.RestClient/Resources/Lists.cs index 4beafaa..4584f41 100644 --- a/Source/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 /// The list public Task GetAsync(string userKey, long listId, bool includeStatistics = true, bool calculateEngagement = false, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/List/GetInfo/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -101,7 +104,11 @@ public Task GetAsync(string userKey, long listId, bool includeStatistics = }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("List/GetInfo") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -117,10 +124,8 @@ public Task GetAsync(string userKey, long listId, bool includeStatistics = /// Client ID of the client in which the list is located. /// The cancellation token /// Enumeration of lists matching the filtering criteria - public Task> GetListsAsync(string userKey, ListStatus? status = null, string name = null, ListsSortBy? sortBy = null, SortDirection? sortDirection = null, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetListsAsync(string userKey, ListStatus? status = null, string name = null, ListsSortBy? sortBy = null, SortDirection? sortDirection = null, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/List/GetList/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -134,7 +139,11 @@ public Task> GetListsAsync(string userKey, ListStatus? status 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, "lists", cancellationToken); + return _client + .PostAsync("List/GetList") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject("lists"); } /// @@ -148,7 +157,6 @@ public Task> GetListsAsync(string userKey, ListStatus? status /// The count of lists matching the filtering criteria public Task GetCountAsync(string userKey, ListStatus? status = null, string name = null, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/List/GetList/"; var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -158,7 +166,11 @@ public Task GetCountAsync(string userKey, ListStatus? status = null, strin 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("List/GetList") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject("count"); } /// @@ -181,8 +193,6 @@ public Task GetCountAsync(string userKey, ListStatus? status = null, strin /// True if the list was updated public Task UpdateAsync(string userKey, long listId, string name = null, string language = null, bool? spamPolicyAccepted = null, ListStatus? status = null, string senderName = null, string senderEmail = null, string goto_oi = null, string goto_di = null, string goto_oo = null, string webhook = null, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/List/SetInfo/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -200,7 +210,11 @@ public Task UpdateAsync(string userKey, long listId, string name = null, s if (webhook != null) parameters.Add(new KeyValuePair("webhook", webhook)); if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("List/SetInfo") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -215,8 +229,6 @@ public Task UpdateAsync(string userKey, long listId, string name = null, s /// True if the field was added to the list public Task AddFieldAsync(string userKey, long listId, string name, FieldType type, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/List/EditStructure/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -227,7 +239,11 @@ public Task AddFieldAsync(string userKey, long listId, string name, FieldT }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("List/EditStructure") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -241,8 +257,6 @@ public Task AddFieldAsync(string userKey, long listId, string name, FieldT /// True if the field was removed from the list public Task DeleteFieldAsync(string userKey, long listId, string name, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/List/EditStructure/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -252,7 +266,11 @@ public Task DeleteFieldAsync(string userKey, long listId, string name, lon }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("List/EditStructure") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -263,10 +281,8 @@ public Task DeleteFieldAsync(string userKey, long listId, string name, lon /// Client ID of the client in which the segment is located. /// The cancellation token /// An enumeration of fields - public async Task> GetFieldsAsync(string userKey, long listId, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) + public async Task GetFieldsAsync(string userKey, long listId, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/List/GetFields/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -274,10 +290,15 @@ public async Task> GetFieldsAsync(string userKey, long li }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - var fieldsStructure = await _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken).ConfigureAwait(false); - if (fieldsStructure == null) return Enumerable.Empty(); + var fieldsStructure = await _client + .PostAsync("List/GetFields") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject() + .ConfigureAwait(false); + if (fieldsStructure == null) return new ListField[] { }; - var fields = fieldsStructure.Select(x => new ListField { Name = x.Key, Type = x.Value.ToString().GetValueFromEnumMember() }); + var fields = fieldsStructure.Select(x => new ListField { Name = x.Key, Type = x.Value.ToString().GetValueFromEnumMember() }).ToArray(); return fields; } @@ -292,8 +313,6 @@ public async Task> GetFieldsAsync(string userKey, long li /// True if the email address was added public Task AddTestEmailAsync(string userKey, long listId, string email, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/List/AddTestEmail/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -302,7 +321,11 @@ public Task AddTestEmailAsync(string userKey, long listId, string email, l }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("List/AddTestEmail") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -316,8 +339,6 @@ public Task AddTestEmailAsync(string userKey, long listId, string email, l /// True if the email address was deleted public Task DeleteTestEmailAsync(string userKey, long listId, string email, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/List/DeleteTestEmail/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -326,7 +347,11 @@ public Task DeleteTestEmailAsync(string userKey, long listId, string email }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("List/DeleteTestEmail") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -337,10 +362,8 @@ public Task DeleteTestEmailAsync(string userKey, long listId, string email /// Client ID of the client in which the list is located. /// The cancellation token /// Enumeration of test email addresses - public Task> GetTestEmailsAsync(string userKey, long listId, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetTestEmailsAsync(string userKey, long listId, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/List/GetTestEmails/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -348,7 +371,11 @@ public Task> GetTestEmailsAsync(string userKey, long listId, }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteArrayRequestAsync(path, parameters, "testemails", cancellationToken); + return _client + .PostAsync("List/GetTestEmails") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject("testemails"); } /// @@ -365,8 +392,6 @@ public Task> GetTestEmailsAsync(string userKey, long listId, /// ID of the new subscriber public Task SubscribeAsync(string userKey, long listId, string email, bool autoResponders = true, bool triggers = true, IEnumerable> customFields = null, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/List/SubscribeEmail/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -386,7 +411,11 @@ public Task SubscribeAsync(string userKey, long listId, string email, bool if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("List/SubscribeEmail") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -400,10 +429,8 @@ public Task SubscribeAsync(string userKey, long listId, string email, bool /// Client ID of the client in which the list is located. /// The cancellation token /// An enumeration of results - public Task> ImportAsync(string userKey, long listId, IEnumerable listMembers, bool autoResponders = true, bool triggers = true, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) + public Task ImportAsync(string userKey, long listId, IEnumerable listMembers, bool autoResponders = true, bool triggers = true, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/List/Import/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -430,7 +457,11 @@ public Task> ImportAsync(string userKey, long listId, if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteArrayRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("List/Import") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -444,8 +475,6 @@ public Task> ImportAsync(string userKey, long listId, /// True if the member was unsubscribed public Task UnsubscribeAsync(string userKey, long listId, string email, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/List/UnsubscribeEmail/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -454,7 +483,11 @@ public Task UnsubscribeAsync(string userKey, long listId, string email, lo }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("List/UnsubscribeEmail") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -468,8 +501,6 @@ public Task UnsubscribeAsync(string userKey, long listId, string email, lo /// True if the member was unsubscribed public Task UnsubscribeAsync(string userKey, long listId, long listMemberId, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/List/UnsubscribeEmail/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -478,7 +509,11 @@ public Task UnsubscribeAsync(string userKey, long listId, long listMemberI }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("List/UnsubscribeEmail") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -492,8 +527,6 @@ public Task UnsubscribeAsync(string userKey, long listId, long listMemberI /// True if the member was deleted public Task DeleteMemberAsync(string userKey, long listId, long listMemberId, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/List/DeleteRecord/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -502,7 +535,11 @@ public Task DeleteMemberAsync(string userKey, long listId, long listMember }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("List/DeleteRecord") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -514,10 +551,8 @@ public Task DeleteMemberAsync(string userKey, long listId, long listMember /// Client ID of the client in which the list is located. /// The cancellation token /// The list mamber - public async Task GetMemberAsync(string userKey, long listId, long listMemberId, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetMemberAsync(string userKey, long listId, long listMemberId, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/List/GetRecord/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -526,8 +561,11 @@ public async Task GetMemberAsync(string userKey, long listId, long l }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - var listMember = await _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken).ConfigureAwait(false); - return listMember; + return _client + .PostAsync("List/GetRecord") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -544,10 +582,8 @@ public async Task GetMemberAsync(string userKey, long listId, long l /// Client ID of the client in which the list is located. /// The cancellation token /// Enumeration of lists matching the filtering criteria - public Task> GetMembersAsync(string userKey, long listId, ListMemberStatus? status = null, string query = null, ListMembersSortBy? sortBy = null, SortDirection? sortDirection = null, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetMembersAsync(string userKey, long listId, ListMemberStatus? status = null, string query = null, ListMembersSortBy? sortBy = null, SortDirection? sortDirection = null, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/List/Show/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -562,7 +598,11 @@ public Task> GetMembersAsync(string userKey, long listId 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, "records", cancellationToken); + return _client + .PostAsync("List/Show") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject("records"); } /// @@ -576,8 +616,6 @@ public Task> GetMembersAsync(string userKey, long listId /// The number of list members matching the filtering criteria public Task GetMembersCountAsync(string userKey, long listId, ListMemberStatus? status = null, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/List/Show/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -587,7 +625,11 @@ public Task GetMembersCountAsync(string userKey, long listId, ListMemberSt if (status.HasValue) parameters.Add(new KeyValuePair("status", status.Value.GetEnumMemberValue())); if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteCountRequestAsync(path, parameters, cancellationToken); + return _client + .PostAsync("List/Show") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject("count"); } /// @@ -602,8 +644,6 @@ public Task GetMembersCountAsync(string userKey, long listId, ListMemberSt /// True if the member was updated public Task UpdateMemberAsync(string userKey, long listId, long listMemberId, IEnumerable> customFields = null, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/List/UpdateRecord/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -621,7 +661,11 @@ public Task UpdateMemberAsync(string userKey, long listId, long listMember if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("List/UpdateRecord") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -639,10 +683,8 @@ public Task UpdateMemberAsync(string userKey, long listId, long listMember /// Client ID of the client in which the list is located. /// The cancellation token /// An enumeration of log items matching the filter criteria - public Task> GetLogsAsync(string userKey, long listId, LogType? logType = null, bool uniques = false, bool totals = false, DateTime? start = null, DateTime? end = null, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetLogsAsync(string userKey, long listId, LogType? logType = null, bool uniques = false, bool totals = false, DateTime? start = null, DateTime? end = null, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/List/GetLog/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -658,7 +700,11 @@ public Task> GetLogsAsync(string userKey, long listId, LogT 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, "logs", cancellationToken); + return _client + .PostAsync("List/GetLog") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject("logs"); } /// @@ -676,8 +722,6 @@ public Task> GetLogsAsync(string userKey, long listId, LogT /// The number of log items matching the filtering criteria public Task GetLogsCountAsync(string userKey, long listId, LogType? logType = null, bool uniques = false, bool totals = false, DateTime? start = null, DateTime? end = null, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/List/GetLog/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -691,7 +735,11 @@ public Task GetLogsCountAsync(string userKey, long listId, LogType? logTyp if (end.HasValue) parameters.Add(new KeyValuePair("end_time", end.Value.ToCakeMailString())); if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteCountRequestAsync(path, parameters, cancellationToken); + return _client + .PostAsync("List/GetLog") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject("count"); } #endregion diff --git a/Source/CakeMail.RestClient/Resources/Mailings.cs b/Source/CakeMail.RestClient/Resources/Mailings.cs index 77222a0..26be355 100644 --- a/Source/CakeMail.RestClient/Resources/Mailings.cs +++ b/Source/CakeMail.RestClient/Resources/Mailings.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,15 @@ public class Mailings { #region Fields - private readonly CakeMailRestClient _cakeMailRestClient; + private readonly IClient _client; #endregion #region Constructor - public Mailings(CakeMailRestClient cakeMailRestClient) + public Mailings(IClient client) { - _cakeMailRestClient = cakeMailRestClient; + _client = client; } #endregion @@ -41,8 +42,6 @@ public Mailings(CakeMailRestClient cakeMailRestClient) /// ID of the new mailing public Task CreateAsync(string userKey, string name, long? campaignId = null, MailingType? type = MailingType.Standard, long? recurringId = null, MessageEncoding? encoding = null, TransferEncoding? transferEncoding = null, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/Mailing/Create/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -55,7 +54,11 @@ public Task CreateAsync(string userKey, string name, long? campaignId = nu if (transferEncoding.HasValue) parameters.Add(new KeyValuePair("transfer_encoding", transferEncoding.Value.GetEnumMemberValue())); if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("Mailing/Create") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -68,8 +71,6 @@ public Task CreateAsync(string userKey, string name, long? campaignId = nu /// True if the mailing is deleted public Task DeleteAsync(string userKey, long mailingId, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/Mailing/Delete/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -77,7 +78,11 @@ public Task DeleteAsync(string userKey, long mailingId, long? clientId = n }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("Mailing/Delete") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -90,8 +95,6 @@ public Task DeleteAsync(string userKey, long mailingId, long? clientId = n /// The mailing public Task GetAsync(string userKey, long mailingId, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/Mailing/GetInfo/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -99,7 +102,11 @@ public Task GetAsync(string userKey, long mailingId, long? clientId = n }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("Mailing/GetInfo") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -121,10 +128,8 @@ public Task GetAsync(string userKey, long mailingId, long? clientId = n /// Client ID of the client in which the mailings are located. /// The cancellation token /// Enumeration of mailings matching the filtering criteria - public Task> GetMailingsAsync(string userKey, MailingStatus? status = null, MailingType? type = null, string name = null, long? listId = null, long? campaignId = null, long? recurringId = null, DateTime? start = null, DateTime? end = null, MailingsSortBy? sortBy = null, SortDirection? sortDirection = null, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetMailingsAsync(string userKey, MailingStatus? status = null, MailingType? type = null, string name = null, long? listId = null, long? campaignId = null, long? recurringId = null, DateTime? start = null, DateTime? end = null, MailingsSortBy? sortBy = null, SortDirection? sortDirection = null, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/Mailing/GetList/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -144,7 +149,11 @@ public Task> GetMailingsAsync(string userKey, MailingStatus 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, "mailings", cancellationToken); + return _client + .PostAsync("Mailing/GetList") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject("mailings"); } /// @@ -164,7 +173,6 @@ public Task> GetMailingsAsync(string userKey, MailingStatus /// The count of mailings matching the filtering criteria public Task GetCountAsync(string userKey, MailingStatus? status = null, MailingType? type = null, string name = null, long? listId = null, long? campaignId = null, long? recurringId = null, DateTime? start = null, DateTime? end = null, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/Mailing/GetList/"; var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -180,7 +188,11 @@ public Task GetCountAsync(string userKey, MailingStatus? status = null, Ma if (end.HasValue) parameters.Add(new KeyValuePair("end_date", end.Value.ToCakeMailString())); if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteCountRequestAsync(path, parameters, cancellationToken); + return _client + .PostAsync("Mailing/GetList") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject("count"); } /// @@ -213,8 +225,6 @@ public Task GetCountAsync(string userKey, MailingStatus? status = null, Ma /// True if the mailing was updated public Task UpdateAsync(string userKey, long mailingId, long? campaignId = null, long? listId = null, long? sublistId = null, string name = null, MailingType? type = null, MessageEncoding? encoding = null, TransferEncoding? transferEncoding = null, string subject = null, string senderEmail = null, string senderName = null, string replyTo = null, string htmlContent = null, string textContent = null, bool? trackOpens = null, bool? trackClicksInHtml = null, bool? trackClicksInText = null, string trackingParameters = null, DateTime? endingOn = null, int? maxRecurrences = null, string recurringConditions = null, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/Mailing/SetInfo/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -242,7 +252,11 @@ public Task UpdateAsync(string userKey, long mailingId, long? campaignId = if (recurringConditions != null) parameters.Add(new KeyValuePair("recurring_conditions", recurringConditions)); if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("Mailing/SetInfo") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -257,8 +271,6 @@ public Task UpdateAsync(string userKey, long mailingId, long? campaignId = /// True if the test email was sent public Task SendTestEmailAsync(string userKey, long mailingId, string recipientEmail, bool separated = false, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/Mailing/SendTestEmail/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -268,7 +280,11 @@ public Task SendTestEmailAsync(string userKey, long mailingId, string reci }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("Mailing/SendTestEmail") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -281,8 +297,6 @@ public Task SendTestEmailAsync(string userKey, long mailingId, string reci /// The multi-part message public Task GetRawEmailMessageAsync(string userKey, long mailingId, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/Mailing/GetEmailMessage/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -290,7 +304,11 @@ public Task GetRawEmailMessageAsync(string userKey, long mailin }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("Mailing/GetEmailMessage") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -303,8 +321,6 @@ public Task GetRawEmailMessageAsync(string userKey, long mailin /// The rendered HTML public Task GetRawHtmlAsync(string userKey, long mailingId, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/Mailing/GetHtmlMessage/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -312,7 +328,11 @@ public Task GetRawHtmlAsync(string userKey, long mailingId, long? client }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("Mailing/GetHtmlMessage") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -325,8 +345,6 @@ public Task GetRawHtmlAsync(string userKey, long mailingId, long? client /// The rendered text public Task GetRawTextAsync(string userKey, long mailingId, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/Mailing/GetTextMessage/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -334,7 +352,11 @@ public Task GetRawTextAsync(string userKey, long mailingId, long? client }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("Mailing/GetTextMessage") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -348,8 +370,6 @@ public Task GetRawTextAsync(string userKey, long mailingId, long? client /// True if the mailing is scheduled public Task ScheduleAsync(string userKey, long mailingId, DateTime? date = null, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/Mailing/Schedule/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -358,7 +378,11 @@ public Task ScheduleAsync(string userKey, long mailingId, DateTime? date = if (date.HasValue) parameters.Add(new KeyValuePair("date", date.Value.ToCakeMailString())); if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("Mailing/Schedule") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -371,8 +395,6 @@ public Task ScheduleAsync(string userKey, long mailingId, DateTime? date = /// True if the mailing is unscheduled public Task UnscheduleAsync(string userKey, long mailingId, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/Mailing/Unschedule/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -380,7 +402,11 @@ public Task UnscheduleAsync(string userKey, long mailingId, long? clientId }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("Mailing/Unschedule") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -393,8 +419,6 @@ public Task UnscheduleAsync(string userKey, long mailingId, long? clientId /// True if the mailing is suspended public Task SuspendAsync(string userKey, long mailingId, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/Mailing/Suspend/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -402,7 +426,11 @@ public Task SuspendAsync(string userKey, long mailingId, long? clientId = }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("Mailing/Suspend") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -415,8 +443,6 @@ public Task SuspendAsync(string userKey, long mailingId, long? clientId = /// True if the mailing is resumed public Task ResumeAsync(string userKey, long mailingId, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/Mailing/Resume/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -424,7 +450,11 @@ public Task ResumeAsync(string userKey, long mailingId, long? clientId = n }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("Mailing/Resume") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -448,10 +478,8 @@ public Task ResumeAsync(string userKey, long mailingId, long? clientId = n /// The current error message is cryptic: Table 'api_cake_logs.mailing_xxxxxxx_big' doesn't exist. /// I was assured in May 2015 that they will improve this message to make it more informative. /// - public Task> GetLogsAsync(string userKey, long mailingId, LogType? logType = null, long? listMemberId = null, bool uniques = false, bool totals = false, DateTime? start = null, DateTime? end = null, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetLogsAsync(string userKey, long mailingId, LogType? logType = null, long? listMemberId = null, bool uniques = false, bool totals = false, DateTime? start = null, DateTime? end = null, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/Mailing/GetLog/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -468,7 +496,11 @@ public Task> GetLogsAsync(string userKey, long mailingId, L 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, "logs", cancellationToken); + return _client + .PostAsync("Mailing/GetLog") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject("logs"); } /// @@ -487,8 +519,6 @@ public Task> GetLogsAsync(string userKey, long mailingId, L /// The number of log items matching the filtering criteria public Task GetLogsCountAsync(string userKey, long mailingId, LogType? logType = null, long? listMemberId = null, bool uniques = false, bool totals = false, DateTime? start = null, DateTime? end = null, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/Mailing/GetLog/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -503,7 +533,11 @@ public Task GetLogsCountAsync(string userKey, long mailingId, LogType? log if (listMemberId.HasValue) parameters.Add(new KeyValuePair("record_id", listMemberId.Value)); if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteCountRequestAsync(path, parameters, cancellationToken); + return _client + .PostAsync("Mailing/GetLog") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject("count"); } /// @@ -519,10 +553,8 @@ public Task GetLogsCountAsync(string userKey, long mailingId, LogType? log /// /// The CakeMail API returns an empty array if you attempt to get the links in a mailing that has not been sent, even if the HTML contains multiple links. /// - public Task> GetLinksAsync(string userKey, long mailingId, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetLinksAsync(string userKey, long mailingId, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/Mailing/GetLinks/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -533,7 +565,11 @@ public Task> GetLinksAsync(string userKey, long mailingId, int 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, "links", cancellationToken); + return _client + .PostAsync("Mailing/GetLinks") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject("links"); } /// @@ -546,8 +582,6 @@ public Task> GetLinksAsync(string userKey, long mailingId, int /// The number of links matching the filtering criteria public Task GetLinksCountAsync(string userKey, long mailingId, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/Mailing/GetLinks/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -556,7 +590,11 @@ public Task GetLinksCountAsync(string userKey, long mailingId, long? clien }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteCountRequestAsync(path, parameters, cancellationToken); + return _client + .PostAsync("Mailing/GetLinks") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject("count"); } /// @@ -569,8 +607,6 @@ public Task GetLinksCountAsync(string userKey, long mailingId, long? clien /// The link public Task GetLinkAsync(string userKey, long linkId, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/Mailing/GetLinkInfo/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -578,7 +614,11 @@ public Task GetLinkAsync(string userKey, long linkId, long? clientId = nul }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("Mailing/GetLinkInfo") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -593,10 +633,8 @@ public Task GetLinkAsync(string userKey, long linkId, long? clientId = nul /// Client ID of the client in which the mailing is located. /// The cancellation token /// An enumeration of links with their statistics matching the filter criteria - public Task> GetLinksWithStatsAsync(string userKey, long mailingId, DateTime? start = null, DateTime? end = null, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetLinksWithStatsAsync(string userKey, long mailingId, DateTime? start = null, DateTime? end = null, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/Mailing/GetLinksLog/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -609,7 +647,11 @@ public Task> GetLinksWithStatsAsync(string userKey, long 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, "links", cancellationToken); + return _client + .PostAsync("Mailing/GetLinksLog") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject("links"); } /// @@ -626,8 +668,6 @@ public Task> GetLinksWithStatsAsync(string userKey, long /// The number of links matching the filter criteria public Task GetLinksWithStatsCountAsync(string userKey, long mailingId, DateTime? start = null, DateTime? end = null, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/Mailing/GetLinksLog/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -640,7 +680,11 @@ public Task GetLinksWithStatsCountAsync(string userKey, long mailingId, Da if (offset > 0) parameters.Add(new KeyValuePair("offset", offset)); if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteCountRequestAsync(path, parameters, cancellationToken); + return _client + .PostAsync("Mailing/GetLinksLog") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject("count"); } #endregion diff --git a/Source/CakeMail.RestClient/Resources/Permissions.cs b/Source/CakeMail.RestClient/Resources/Permissions.cs index 247e3c0..4820bf2 100644 --- a/Source/CakeMail.RestClient/Resources/Permissions.cs +++ b/Source/CakeMail.RestClient/Resources/Permissions.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using CakeMail.RestClient.Utilities; +using Pathoschild.Http.Client; +using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -9,15 +11,15 @@ public class Permissions { #region Fields - private readonly CakeMailRestClient _cakeMailRestClient; + private readonly IClient _client; #endregion #region Constructor - public Permissions(CakeMailRestClient cakeMailRestClient) + public Permissions(IClient client) { - _cakeMailRestClient = cakeMailRestClient; + _client = client; } #endregion @@ -32,10 +34,8 @@ public Permissions(CakeMailRestClient cakeMailRestClient) /// ID of the client. /// The cancellation token /// An enumeration of permissions - public Task> GetUserPermissionsAsync(string userKey, long userId, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetUserPermissionsAsync(string userKey, long userId, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/Permission/GetPermissions/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -43,7 +43,11 @@ public Task> GetUserPermissionsAsync(string userKey, long us }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteArrayRequestAsync(path, parameters, "permissions", cancellationToken); + return _client + .PostAsync("Permission/GetPermissions") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject("permissions"); } /// @@ -57,8 +61,6 @@ public Task> GetUserPermissionsAsync(string userKey, long us /// True if the operation succeeded public Task SetUserPermissionsAsync(string userKey, long userId, IEnumerable permissions, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/Permission/SetPermissions/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -71,7 +73,11 @@ public Task SetUserPermissionsAsync(string userKey, long userId, IEnumerab if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("Permission/SetPermissions") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } #endregion diff --git a/Source/CakeMail.RestClient/Resources/Relays.cs b/Source/CakeMail.RestClient/Resources/Relays.cs index c6211fd..3910d04 100644 --- a/Source/CakeMail.RestClient/Resources/Relays.cs +++ b/Source/CakeMail.RestClient/Resources/Relays.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,15 @@ public class Relays { #region Fields - private readonly CakeMailRestClient _cakeMailRestClient; + private readonly IClient _client; #endregion #region Constructor - public Relays(CakeMailRestClient cakeMailRestClient) + public Relays(IClient client) { - _cakeMailRestClient = cakeMailRestClient; + _client = client; } #endregion @@ -42,8 +43,6 @@ public Relays(CakeMailRestClient cakeMailRestClient) /// True if the email is sent public Task SendWithoutTrackingAsync(string userKey, string recipientEmailAddress, string subject, string html, string text, string senderEmail, string senderName = null, MessageEncoding? encoding = null, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/Relay/Send/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -60,7 +59,11 @@ public Task SendWithoutTrackingAsync(string userKey, string recipientEmail if (encoding.HasValue) parameters.Add(new KeyValuePair("encoding", encoding.Value.GetEnumMemberValue())); if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("Relay/Send") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -80,8 +83,6 @@ public Task SendWithoutTrackingAsync(string userKey, string recipientEmail /// True if the email is sent public Task SendWithTrackingAsync(string userKey, long trackingId, string recipientEmailAddress, string subject, string html, string text, string senderEmail, string senderName = null, MessageEncoding? encoding = null, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/Relay/Send/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -99,7 +100,11 @@ public Task SendWithTrackingAsync(string userKey, long trackingId, string if (encoding.HasValue) parameters.Add(new KeyValuePair("encoding", encoding.Value.GetEnumMemberValue())); if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("Relay/Send") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -114,7 +119,7 @@ public Task SendWithTrackingAsync(string userKey, long trackingId, string /// Client ID of the client in which the mailing is located. /// The cancellation token /// An enumeration of log items matching the filter criteria - public Task> GetSentLogsAsync(string userKey, long? trackingId = null, DateTime? start = null, DateTime? end = null, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetSentLogsAsync(string userKey, long? trackingId = null, DateTime? start = null, DateTime? end = null, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { return GetLogsAsync(userKey, "sent", "sent_logs", trackingId, start, end, limit, offset, clientId, cancellationToken); } @@ -131,7 +136,7 @@ public Task> GetSentLogsAsync(string userKey, long? tracki /// Client ID of the client in which the mailing is located. /// The cancellation token /// An enumeration of log items matching the filter criteria - public Task> GetOpenLogsAsync(string userKey, long? trackingId = null, DateTime? start = null, DateTime? end = null, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetOpenLogsAsync(string userKey, long? trackingId = null, DateTime? start = null, DateTime? end = null, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { return GetLogsAsync(userKey, "open", "open_logs", trackingId, start, end, limit, offset, clientId, cancellationToken); } @@ -148,7 +153,7 @@ public Task> GetOpenLogsAsync(string userKey, long? tr /// Client ID of the client in which the mailing is located. /// The cancellation token /// An enumeration of log items matching the filter criteria - public Task> GetClickLogsAsync(string userKey, long? trackingId = null, DateTime? start = null, DateTime? end = null, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetClickLogsAsync(string userKey, long? trackingId = null, DateTime? start = null, DateTime? end = null, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { return GetLogsAsync(userKey, "clickthru", "clickthru_logs", trackingId, start, end, limit, offset, clientId, cancellationToken); } @@ -165,7 +170,7 @@ public Task> GetClickLogsAsync(string userKey, long? /// Client ID of the client in which the mailing is located. /// The cancellation token /// An enumeration of log items matching the filter criteria - public Task> GetBounceLogsAsync(string userKey, long? trackingId = null, DateTime? start = null, DateTime? end = null, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetBounceLogsAsync(string userKey, long? trackingId = null, DateTime? start = null, DateTime? end = null, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { return GetLogsAsync(userKey, "bounce", "bounce_logs", trackingId, start, end, limit, offset, clientId, cancellationToken); } @@ -174,10 +179,9 @@ public Task> GetBounceLogsAsync(string userKey, long #region PRIVATE METHODS - private Task> GetLogsAsync(string userKey, string logType, string arrayPropertyName, long? trackingId = null, DateTime? start = null, DateTime? end = null, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) where T : RelayLog, new() + private Task GetLogsAsync(string userKey, string logType, string arrayPropertyName, long? trackingId = null, DateTime? start = null, DateTime? end = null, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) + where T : RelayLog, new() { - string path = "/Relay/GetLogs/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -190,7 +194,11 @@ private Task> GetLogsAsync(string userKey, string logType, str 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, arrayPropertyName, cancellationToken); + return _client + .PostAsync("Relay/GetLogs") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(arrayPropertyName); } #endregion diff --git a/Source/CakeMail.RestClient/Resources/Segments.cs b/Source/CakeMail.RestClient/Resources/Segments.cs index 257a7db..8cd87a9 100644 --- a/Source/CakeMail.RestClient/Resources/Segments.cs +++ b/Source/CakeMail.RestClient/Resources/Segments.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 Segments { #region Fields - private readonly CakeMailRestClient _cakeMailRestClient; + private readonly IClient _client; #endregion #region Constructor - public Segments(CakeMailRestClient cakeMailRestClient) + public Segments(IClient client) { - _cakeMailRestClient = cakeMailRestClient; + _client = client; } #endregion @@ -43,8 +45,6 @@ public Segments(CakeMailRestClient cakeMailRestClient) /// public Task CreateAsync(string userKey, long listId, string name, string query = null, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/List/CreateSublist/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -54,7 +54,11 @@ public Task CreateAsync(string userKey, long listId, string name, string q if (query != null) parameters.Add(new KeyValuePair("query", query)); if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("List/CreateSublist") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -69,8 +73,6 @@ public Task CreateAsync(string userKey, long listId, string name, string q /// The segment public Task GetAsync(string userKey, long segmentId, bool includeStatistics = true, bool calculateEngagement = false, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/List/GetInfo/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -80,7 +82,11 @@ public Task GetAsync(string userKey, long segmentId, bool includeStatis }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("List/GetInfo") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -97,8 +103,6 @@ public Task GetAsync(string userKey, long segmentId, bool includeStatis /// A segment is sometimes referred to as a 'sub-list' public Task UpdateAsync(string userKey, long segmentId, long listId, string name = null, string query = null, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/List/SetInfo/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -109,7 +113,11 @@ public Task UpdateAsync(string userKey, long segmentId, long listId, strin if (query != null) parameters.Add(new KeyValuePair("query", query)); if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("List/SetInfo") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -122,8 +130,6 @@ public Task UpdateAsync(string userKey, long segmentId, long listId, strin /// True if the segment was deleted public Task DeleteAsync(string userKey, long segmentId, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/List/DeleteSublist/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -131,7 +137,11 @@ public Task DeleteAsync(string userKey, long segmentId, long? clientId = n }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("List/DeleteSublist") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -145,10 +155,8 @@ public Task DeleteAsync(string userKey, long segmentId, long? clientId = n /// ID of the client /// The cancellation token /// Enumeration of segments matching the filtering criteria - public Task> GetSegmentsAsync(string userKey, long listId, int? limit = 0, int? offset = 0, bool includeDetails = true, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetSegmentsAsync(string userKey, long listId, int? limit = 0, int? offset = 0, bool includeDetails = true, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/List/GetSublists/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -160,7 +168,11 @@ public Task> GetSegmentsAsync(string userKey, long listId, 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, "sublists", cancellationToken); + return _client + .PostAsync("List/GetSublists") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject("sublists"); } /// @@ -173,8 +185,6 @@ public Task> GetSegmentsAsync(string userKey, long listId, /// The count of campaigns matching the filtering criteria public Task GetCountAsync(string userKey, long listId, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/List/GetList/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -183,7 +193,11 @@ public Task GetCountAsync(string userKey, long listId, long? clientId = nu }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteCountRequestAsync(path, parameters, cancellationToken); + return _client + .PostAsync("List/GetList") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject("count"); } #endregion diff --git a/Source/CakeMail.RestClient/Resources/SuppressionLists.cs b/Source/CakeMail.RestClient/Resources/SuppressionLists.cs index c842362..c96f712 100644 --- a/Source/CakeMail.RestClient/Resources/SuppressionLists.cs +++ b/Source/CakeMail.RestClient/Resources/SuppressionLists.cs @@ -1,4 +1,6 @@ using CakeMail.RestClient.Models; +using CakeMail.RestClient.Utilities; +using Pathoschild.Http.Client; using System.Collections.Generic; using System.Dynamic; using System.Linq; @@ -11,15 +13,15 @@ public class SuppressionLists { #region Fields - private readonly CakeMailRestClient _cakeMailRestClient; + private readonly IClient _client; #endregion #region Constructor - public SuppressionLists(CakeMailRestClient cakeMailRestClient) + public SuppressionLists(IClient client) { - _cakeMailRestClient = cakeMailRestClient; + _client = client; } #endregion @@ -34,10 +36,8 @@ public SuppressionLists(CakeMailRestClient cakeMailRestClient) /// ID of the client. /// The cancellation token /// An enumeration of results. Each item in this enumeration indicates the result of adding an email address to the suppression list. - public Task> AddEmailAddressesAsync(string userKey, IEnumerable emailAddresses, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) + public Task AddEmailAddressesAsync(string userKey, IEnumerable emailAddresses, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/SuppressionList/ImportEmails/"; - var parameters = new List> { new KeyValuePair("user_key", userKey) @@ -52,7 +52,11 @@ public Task> AddEmailAddressesAsync(string user if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteArrayRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("SuppressionList/ImportEmails") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -63,10 +67,8 @@ public Task> AddEmailAddressesAsync(string user /// ID of the client. /// The cancellation token /// An enumeration of results. Each item in this enumeration indicates the result of adding a domain to the suppression list. - public Task> AddDomainsAsync(string userKey, IEnumerable domains, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) + public Task AddDomainsAsync(string userKey, IEnumerable domains, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/SuppressionList/ImportDomains/"; - var parameters = new List> { new KeyValuePair("user_key", userKey) @@ -81,7 +83,11 @@ public Task> AddDomainsAsync(string userKey, I if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteArrayRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("SuppressionList/ImportDomains") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -92,10 +98,8 @@ public Task> AddDomainsAsync(string userKey, I /// Client ID of the client. /// The cancellation token /// An enumeration of results. Each item in this enumeration indicates the result of adding a localpart to the suppression list. - public Task> AddLocalPartsAsync(string userKey, IEnumerable localParts, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) + public Task AddLocalPartsAsync(string userKey, IEnumerable localParts, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/SuppressionList/ImportLocalparts/"; - var parameters = new List> { new KeyValuePair("user_key", userKey) @@ -110,7 +114,11 @@ public Task> AddLocalPartsAsync(string user if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteArrayRequestAsync(path, parameters, "localparts", cancellationToken); + return _client + .PostAsync("SuppressionList/ImportLocalparts") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -121,10 +129,8 @@ public Task> AddLocalPartsAsync(string user /// ID of the client. /// The cancellation token /// An enumeration of results. Each item in this enumeration indicates the result of removing an email address from the suppression list. - public Task> RemoveEmailAddressesAsync(string userKey, IEnumerable emailAddresses, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) + public Task RemoveEmailAddressesAsync(string userKey, IEnumerable emailAddresses, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/SuppressionList/DeleteEmails/"; - var parameters = new List> { new KeyValuePair("user_key", userKey) @@ -139,7 +145,11 @@ public Task> RemoveEmailAddressesAsync(string u if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteArrayRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("SuppressionList/DeleteEmails") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -150,10 +160,8 @@ public Task> RemoveEmailAddressesAsync(string u /// ID of the client. /// The cancellation token /// An enumeration of results. Each item in this enumeration indicates the result of removing a domain from the suppression list. - public Task> RemoveDomainsAsync(string userKey, IEnumerable domains, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) + public Task RemoveDomainsAsync(string userKey, IEnumerable domains, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/SuppressionList/DeleteDomains/"; - var parameters = new List> { new KeyValuePair("user_key", userKey) @@ -168,7 +176,11 @@ public Task> RemoveDomainsAsync(string userKey if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteArrayRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("SuppressionList/DeleteDomains") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -179,10 +191,8 @@ public Task> RemoveDomainsAsync(string userKey /// ID of the client. /// The cancellation token /// An enumeration of results. Each item in this enumeration indicates the result of removing a localpart from the suppression list. - public Task> RemoveLocalPartsAsync(string userKey, IEnumerable localParts, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) + public Task RemoveLocalPartsAsync(string userKey, IEnumerable localParts, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/SuppressionList/DeleteLocalparts/"; - var parameters = new List> { new KeyValuePair("user_key", userKey) @@ -197,7 +207,11 @@ public Task> RemoveLocalPartsAsync(string u if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteArrayRequestAsync(path, parameters, "localparts", cancellationToken); + return _client + .PostAsync("SuppressionList/DeleteLocalparts") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -209,10 +223,8 @@ public Task> RemoveLocalPartsAsync(string u /// ID of the client. /// The cancellation token /// An enumeration of addresses. The result also indicates how each email address ended up on the suppression list. - public Task> GetEmailAddressesAsync(string userKey, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetEmailAddressesAsync(string userKey, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/SuppressionList/ExportEmails/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -222,7 +234,11 @@ public Task> GetEmailAddressesAsync(string userKey, 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, "emails", cancellationToken); + return _client + .PostAsync("SuppressionList/ExportEmails") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject("emails"); } /// @@ -234,10 +250,8 @@ public Task> GetEmailAddressesAsync(string userKey, /// ID of the client. /// The cancellation token /// An enumeration of domains. - public async Task> GetDomainsAsync(string userKey, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) + public async Task GetDomainsAsync(string userKey, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/SuppressionList/ExportDomains/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -247,7 +261,12 @@ public async Task> GetDomainsAsync(string userKey, int? limi if (offset > 0) parameters.Add(new KeyValuePair("offset", offset)); if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - var result = await _cakeMailRestClient.ExecuteArrayRequestAsync(path, parameters, "domains", cancellationToken).ConfigureAwait(false); + var result = await _client + .PostAsync("SuppressionList/ExportDomains") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject("domains") + .ConfigureAwait(false); var domains = (from r in result select r.Single(p => p.Key == "domain").Value.ToString()).ToArray(); return domains; @@ -262,10 +281,8 @@ public async Task> GetDomainsAsync(string userKey, int? limi /// ID of the client. /// The cancellation token /// An enumeration of localparts. - public async Task> GetLocalPartsAsync(string userKey, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) + public async Task GetLocalPartsAsync(string userKey, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/SuppressionList/ExportLocalparts/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -275,7 +292,12 @@ public async Task> GetLocalPartsAsync(string userKey, int? l if (offset > 0) parameters.Add(new KeyValuePair("offset", offset)); if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - var result = await _cakeMailRestClient.ExecuteArrayRequestAsync(path, parameters, "localparts", cancellationToken).ConfigureAwait(false); + var result = await _client + .PostAsync("SuppressionList/ExportLocalparts") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject("localparts") + .ConfigureAwait(false); var localParts = (from r in result select r.Single(p => p.Key == "localpart").Value.ToString()).ToArray(); return localParts; @@ -290,8 +312,6 @@ public async Task> GetLocalPartsAsync(string userKey, int? l /// The number of email addresses on the suppresssion list public Task GetEmailAddressesCountAsync(string userKey, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/SuppressionList/ExportEmails/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -299,7 +319,11 @@ public Task GetEmailAddressesCountAsync(string userKey, long? clientId = n }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteCountRequestAsync(path, parameters, cancellationToken); + return _client + .PostAsync("SuppressionList/ExportEmails") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject("count"); } /// @@ -311,8 +335,6 @@ public Task GetEmailAddressesCountAsync(string userKey, long? clientId = n /// The number of domains on the suppresssion list public Task GetDomainsCountAsync(string userKey, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/SuppressionList/ExportDomains/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -320,7 +342,11 @@ public Task GetDomainsCountAsync(string userKey, long? clientId = null, Ca }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteCountRequestAsync(path, parameters, cancellationToken); + return _client + .PostAsync("SuppressionList/ExportDomains") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject("count"); } /// @@ -332,8 +358,6 @@ public Task GetDomainsCountAsync(string userKey, long? clientId = null, Ca /// The number of localparts on the suppresssion list public Task GetLocalPartsCountAsync(string userKey, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/SuppressionList/ExportLocalparts/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -341,7 +365,11 @@ public Task GetLocalPartsCountAsync(string userKey, long? clientId = null, }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteCountRequestAsync(path, parameters, cancellationToken); + return _client + .PostAsync("SuppressionList/ExportLocalparts") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject("count"); } #endregion diff --git a/Source/CakeMail.RestClient/Resources/Templates.cs b/Source/CakeMail.RestClient/Resources/Templates.cs index 7075c75..1c2d12d 100644 --- a/Source/CakeMail.RestClient/Resources/Templates.cs +++ b/Source/CakeMail.RestClient/Resources/Templates.cs @@ -1,4 +1,6 @@ using CakeMail.RestClient.Models; +using CakeMail.RestClient.Utilities; +using Pathoschild.Http.Client; using System.Collections.Generic; using System.Linq; using System.Threading; @@ -10,15 +12,15 @@ public class Templates { #region Fields - private readonly CakeMailRestClient _cakeMailRestClient; + private readonly IClient _client; #endregion #region Constructor - public Templates(CakeMailRestClient cakeMailRestClient) + public Templates(IClient client) { - _cakeMailRestClient = cakeMailRestClient; + _client = client; } #endregion @@ -37,8 +39,6 @@ public Templates(CakeMailRestClient cakeMailRestClient) /// ID of the new template category public Task CreateCategoryAsync(string userKey, IDictionary labels, bool isVisibleByDefault = true, bool templatesCanBeCopied = true, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/TemplateV2/CreateCategory/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -59,7 +59,11 @@ public Task CreateCategoryAsync(string userKey, IDictionary(path, parameters, "id", cancellationToken); + return _client + .PostAsync("TemplateV2/CreateCategory") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject("id"); } /// @@ -72,8 +76,6 @@ public Task CreateCategoryAsync(string userKey, IDictionaryTrue if the template category is deleted public async Task DeleteCategoryAsync(string userKey, long categoryId, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/TemplateV2/DeleteCategory/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -84,7 +86,13 @@ public async Task DeleteCategoryAsync(string userKey, long categoryId, lon // The data returned when deleting a category is a little bit unusual // Instead of returning a boolean value to indicate success, it returns an empty array!!! // For example: {"status":"success","data":[]} - await _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken).ConfigureAwait(false); + await _client + .PostAsync("TemplateV2/DeleteCategory") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsResponse() + .ConfigureAwait(false); + return true; } @@ -98,8 +106,6 @@ public async Task DeleteCategoryAsync(string userKey, long categoryId, lon /// The category public Task GetCategoryAsync(string userKey, long categoryId, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/TemplateV2/GetCategory/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -107,7 +113,11 @@ public Task GetCategoryAsync(string userKey, long categoryId, }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("TemplateV2/GetCategory") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -119,10 +129,8 @@ public Task GetCategoryAsync(string userKey, long categoryId, /// Client ID of the client in which the categories are located. /// The cancellation token /// Enumeration of categories matching the filtering criteria - public Task> GetCategoriesAsync(string userKey, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetCategoriesAsync(string userKey, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/TemplateV2/GetCategories/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -132,7 +140,11 @@ public Task> GetCategoriesAsync(string userKey, in 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, "categories", cancellationToken); + return _client + .PostAsync("TemplateV2/GetCategories") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject("categories"); } /// @@ -144,8 +156,6 @@ public Task> GetCategoriesAsync(string userKey, in /// The count of categories matching the filtering criteria public Task GetCategoriesCountAsync(string userKey, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/TemplateV2/GetCategories/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -153,7 +163,11 @@ public Task GetCategoriesCountAsync(string userKey, long? clientId = null, }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteCountRequestAsync(path, parameters, cancellationToken); + return _client + .PostAsync("TemplateV2/GetCategories") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject("count"); } /// @@ -169,8 +183,6 @@ public Task GetCategoriesCountAsync(string userKey, long? clientId = null, /// True if the category was updated public Task UpdateCategoryAsync(string userKey, long categoryId, IDictionary labels, bool isVisibleByDefault = true, bool templatesCanBeCopied = true, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/TemplateV2/SetCategory/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -188,7 +200,11 @@ public Task UpdateCategoryAsync(string userKey, long categoryId, IDictiona if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("TemplateV2/SetCategory") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -201,10 +217,8 @@ public Task UpdateCategoryAsync(string userKey, long categoryId, IDictiona /// ID of the client in which the category is located. /// The cancellation token /// An enumeration of permissions - public Task> GetCategoryVisibilityAsync(string userKey, long categoryId, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetCategoryVisibilityAsync(string userKey, long categoryId, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/TemplateV2/GetCategoryVisibility/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -215,7 +229,11 @@ public Task> GetCategoryVisibilityAsync( 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("TemplateV2/GetCategoryVisibility") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject("clients"); } /// @@ -228,8 +246,6 @@ public Task> GetCategoryVisibilityAsync( /// The count of permissions matching the filtering criteria public Task GetCategoryVisibilityCountAsync(string userKey, long categoryId, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/TemplateV2/GetCategoryVisibility/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -238,7 +254,11 @@ public Task GetCategoryVisibilityCountAsync(string userKey, long categoryI }; if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteCountRequestAsync(path, parameters, cancellationToken); + return _client + .PostAsync("TemplateV2/GetCategoryVisibility") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject("count"); } /// @@ -252,8 +272,6 @@ public Task GetCategoryVisibilityCountAsync(string userKey, long categoryI /// True if the permissions are successfully updated public Task SetCategoryVisibilityAsync(string userKey, long categoryId, IDictionary clientVisibility, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - var path = "/TemplateV2/SetCategoryVisibility/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -270,7 +288,11 @@ public Task SetCategoryVisibilityAsync(string userKey, long categoryId, ID if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value)); - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken); + return _client + .PostAsync("TemplateV2/SetCategoryVisibility") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject(); } /// @@ -285,8 +307,6 @@ public Task SetCategoryVisibilityAsync(string userKey, long categoryId, ID /// ID of the new template public Task CreateAsync(string userKey, IDictionary labels, string content, long categoryId, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/TemplateV2/CreateTemplate/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -307,7 +327,11 @@ public Task CreateAsync(string userKey, IDictionary labels // The data returned when creating a new template is a little bit unusual // Instead of simply returning the unique identifier of the new record like all the other 'Create' methods, for example: {"status":"success","data":"4593766"} // this method return an object with a single property called 'id' containing the unique identifier of the new record, like this: {"status":"success","data":{"id":"14052"}} - return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, "id", cancellationToken); + return _client + .PostAsync("TemplateV2/CreateTemplate") + .WithFormUrlEncodedBody(parameters) + .WithCancellationToken(cancellationToken) + .AsCakeMailObject("id"); } /// @@ -320,8 +344,6 @@ public Task CreateAsync(string userKey, IDictionary labels /// True if the template is deleted public async Task DeleteAsync(string userKey, long templateId, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken)) { - string path = "/TemplateV2/DeleteTemplate/"; - var parameters = new List> { new KeyValuePair("user_key", userKey), @@ -332,7 +354,12 @@ public async Task DeleteAsync(string userKey, long templateId, long? clien // The data returned when deleting a template is a little bit unusual // Instead of returning a boolean value to indicate success, it returns an empty array!!! // For example: {"status":"success","data":[]} - await _cakeMailRestClient.ExecuteRequestAsync(path, parameters, cancellationToken).ConfigureAwait(false); + await _client + .PostAsync("TemplateV2/DeleteTemplate") + .WithCancellationToken(cancellationToken) + .AsResponse() + .ConfigureAwait(false); + return true; } @@ -346,8 +373,6 @@ public async Task DeleteAsync(string userKey, long templateId, long? clien /// The template public Task