public static async Task ExecuteAllMethods(ICakeMailRestClient client, string userKey, long clientId, TextWriter log, CancellationToken cancellationToken)
        {
            await log.WriteLineAsync("\n***** COUNTRIES *****").ConfigureAwait(false);

            var countries = await client.Countries.GetListAsync().ConfigureAwait(false);

            await log.WriteLineAsync($"Retrieved all countries. There are {countries.Count()} countries.").ConfigureAwait(false);

            var canada = countries.Single(country => country.EnglishName == "Canada");
            await log.WriteLineAsync($"Canada --> Id: {canada.Id}").ConfigureAwait(false);

            var canadianProvinces = await client.Countries.GetProvincesAsync(canada.Id).ConfigureAwait(false);

            await log.WriteLineAsync($"There are {canadianProvinces.Count()} canadian provinces/territories/etc.").ConfigureAwait(false);

            var quebec = canadianProvinces.Single(province => province.EnglishName == "Quebec");
            await log.WriteLineAsync($"Quebec --> Id: {quebec.Id}").ConfigureAwait(false);

            var usa = countries.Single(country => country.EnglishName == "United States");
            await log.WriteLineAsync($"USA --> Id: {usa.Id}").ConfigureAwait(false);

            var americanStates = await client.Countries.GetProvincesAsync(usa.Id).ConfigureAwait(false);

            await log.WriteLineAsync($"There are {americanStates.Count()} american states/territories/etc.").ConfigureAwait(false);

            var georgia = americanStates.Single(province => province.EnglishName == "Georgia");
            await log.WriteLineAsync($"Georgia --> Id: {georgia.Id}").ConfigureAwait(false);

            var florida = americanStates.Single(province => province.EnglishName == "Florida");
            await log.WriteLineAsync($"Florida --> Id: {florida.Id}").ConfigureAwait(false);
        }
示例#2
0
        public static async Task ExecuteAllMethods(ICakeMailRestClient client, string userKey, long clientId, TextWriter log, CancellationToken cancellationToken)
        {
            await log.WriteLineAsync("\n***** SUPPRESSION LISTS *****").ConfigureAwait(false);

            var suppressEmailsResult = await client.SuppressionLists.AddEmailAddressesAsync(userKey, new string[] { "*****@*****.**", "*****@*****.**" }, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Email addresses suppressed: {string.Join(", ", suppressEmailsResult.Select(r => string.Format("{0}={1}", r.Email, string.IsNullOrEmpty(r.ErrorMessage) ? "success" : r.ErrorMessage)))}").ConfigureAwait(false);

            var suppressedDomainResult = await client.SuppressionLists.AddDomainsAsync(userKey, new[] { "qwerty.com", "azerty.com" }, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Email domains suppressed: {string.Join(", ", suppressedDomainResult.Select(r => string.Format("{0}={1}", r.Domain, string.IsNullOrEmpty(r.ErrorMessage) ? "success" : r.ErrorMessage)))}").ConfigureAwait(false);

            var suppressedLocalPartsResult = await client.SuppressionLists.AddLocalPartsAsync(userKey, new[] { "qwerty", "azerty" }, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Email localparts suppressed: {string.Join(", ", suppressedLocalPartsResult.Select(r => string.Format("{0}={1}", r.LocalPart, string.IsNullOrEmpty(r.ErrorMessage) ? "success" : r.ErrorMessage)))}").ConfigureAwait(false);

            var suppressedEmails = await client.SuppressionLists.GetEmailAddressesAsync(userKey, 0, 0, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Retrieved suppressed email addresses: {string.Join(", ", suppressedEmails.Select(r => r.Email))}").ConfigureAwait(false);

            var suppressedDomains = await client.SuppressionLists.GetDomainsAsync(userKey, 0, 0, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Retrieved suppressed email domains: {string.Join(", ", suppressedDomains)}").ConfigureAwait(false);

            var suppressedLocalParts = await client.SuppressionLists.GetLocalPartsAsync(userKey, 0, 0, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Retrieved suppressed localparts: {string.Join(", ", suppressedLocalParts)}").ConfigureAwait(false);
        }
示例#3
0
        public static async Task ExecuteAllMethods(ICakeMailRestClient client, string userKey, long clientId, TextWriter log, CancellationToken cancellationToken)
        {
            await log.WriteLineAsync("\n***** USERS *****").ConfigureAwait(false);

            var users = await client.Users.GetUsersAsync(userKey, UserStatus.Active, null, null, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"All users retrieved. Count = {users.Count()}").ConfigureAwait(false);

            var usersCount = await client.Users.GetCountAsync(userKey, UserStatus.Active, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Users count = {usersCount}").ConfigureAwait(false);

            var userId = await client.Users.CreateAsync(userKey, string.Format("bogus{0:00}@dummy.com", usersCount), "Integration", "Testing", "Test", "4045555555", "7701234567", "en_US", "dummy_password", 542, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"New user created. Id: {userId}").ConfigureAwait(false);

            var user = await client.Users.GetAsync(userKey, userId, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"User retrieved: Name = {user.FirstName} {user.LastName}").ConfigureAwait(false);

            var deactivated = await client.Users.DeactivateAsync(userKey, userId, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"User deactivate: {(deactivated ? "success" : "failed")}").ConfigureAwait(false);

            var deleted = await client.Users.DeleteAsync(userKey, userId, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"User deleted: {(deleted ? "success" : "failed")}").ConfigureAwait(false);
        }
示例#4
0
        private static async Task <int> ExecuteAsync(ICakeMailRestClient client, string userKey, long clientId, CancellationTokenSource cts, Func <ICakeMailRestClient, string, long, TextWriter, CancellationToken, Task> asyncTask)
        {
            var log = new StringWriter();

            try
            {
                await asyncTask(client, userKey, clientId, log, cts.Token).ConfigureAwait(false);
            }
            catch (OperationCanceledException)
            {
                await log.WriteLineAsync($"-----> TASK CANCELLED").ConfigureAwait(false);

                return(1223);                // Cancelled.
            }
            catch (Exception e)
            {
                await log.WriteLineAsync($"-----> AN EXCEPTION OCCURED: {e.GetBaseException().Message}").ConfigureAwait(false);

                throw;
            }
            finally
            {
                await Console.Out.WriteLineAsync(log.ToString()).ConfigureAwait(false);
            }

            return(0);              // Success
        }
示例#5
0
        public static async Task ExecuteAllMethods(ICakeMailRestClient client, string userKey, long clientId, TextWriter log, CancellationToken cancellationToken)
        {
            await log.WriteLineAsync("\n***** PERMISSIONS *****").ConfigureAwait(false);

            var users = await client.Users.GetUsersAsync(userKey, UserStatus.Active, null, null, clientId).ConfigureAwait(false);

            await log.WriteLineAsync("All users retrieved").ConfigureAwait(false);

            var user = users.First();
            await log.WriteLineAsync($"For testing purposes, we selected {user.FirstName} {user.LastName}").ConfigureAwait(false);

            var originalUserPermissions = await client.Permissions.GetUserPermissionsAsync(userKey, user.Id, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Current user permissions: {string.Join(", ", originalUserPermissions)}").ConfigureAwait(false);

            var updated = await client.Permissions.SetUserPermissionsAsync(userKey, user.Id, new[] { "admin_settings" }, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Permissions updated: {(updated ? "success" : "failed")}").ConfigureAwait(false);

            var newUserPermissions = await client.Permissions.GetUserPermissionsAsync(userKey, user.Id, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"New user permissions: {string.Join(", ", newUserPermissions)}").ConfigureAwait(false);

            updated = await client.Permissions.SetUserPermissionsAsync(userKey, user.Id, originalUserPermissions, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Permissions reset to original values: {(updated ? "success" : "failed")}").ConfigureAwait(false);
        }
示例#6
0
        public static async Task ExecuteAllMethods(ICakeMailRestClient client, string userKey, long clientId, TextWriter log, CancellationToken cancellationToken)
        {
            await log.WriteLineAsync("\n***** RELAYS *****").ConfigureAwait(false);

            var sent = await client.Relays.SendWithoutTrackingAsync(userKey, "*****@*****.**", "Sent from integration test", "<html><body>Sent from integration test (HTML)</body></html>", "Sent from integration test (TEXT)", "*****@*****.**", "Integration Testing", null, null, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Relay sent: {(sent ? "success" : "failed")}").ConfigureAwait(false);

            var sentLogs = await client.Relays.GetSentLogsAsync(userKey, null, null, null, null, null, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Sent Logs: {sentLogs.Count()}").ConfigureAwait(false);
        }
示例#7
0
        public static async Task ExecuteAllMethods(ICakeMailRestClient client, string userKey, long clientId, TextWriter log, CancellationToken cancellationToken)
        {
            await log.WriteLineAsync("\n***** TIMEZONES *****").ConfigureAwait(false);

            var timezones = await client.Timezones.GetAllAsync(cancellationToken).ConfigureAwait(false);

            await log.WriteLineAsync($"Retrieved all timezones. There are {timezones.Count()} timezones.").ConfigureAwait(false);

            var utcTimezones = timezones.Where(tz => tz.Name.Contains("UTC")).ToArray();
            await log.WriteLineAsync("The following timezones contain the word UTC in their name:").ConfigureAwait(false);

            await log.WriteLineAsync(string.Join(", ", utcTimezones.Select(tz => $"{tz.Name} ({tz.Id})"))).ConfigureAwait(false);
        }
示例#8
0
        public static async Task ExecuteAllMethods(ICakeMailRestClient client, string userKey, long clientId, TextWriter log, CancellationToken cancellationToken)
        {
            await log.WriteLineAsync("\n***** CLIENT *****").ConfigureAwait(false);

            var clientsCount = await client.Clients.GetCountAsync(userKey, null, null, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Clients count = {clientsCount}").ConfigureAwait(false);

            var adminEmail   = string.Format("admin{0:00}+{1:0000}@integrationtesting.com", clientsCount, (new Random()).Next(9999));
            var confirmation = await client.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);

            await log.WriteLineAsync($"New client created. Confirmation code: {confirmation}").ConfigureAwait(false);

            var unconfirmedClient = await client.Clients.GetAsync(userKey, confirmation).ConfigureAwait(false);

            await log.WriteLineAsync($"Information about this unconfirmed client: Name = {unconfirmedClient.Name}").ConfigureAwait(false);

            var registrationInfo = await client.Clients.ConfirmAsync(confirmation).ConfigureAwait(false);

            await log.WriteLineAsync($"Client has been confirmed. Id = {registrationInfo.ClientId}").ConfigureAwait(false);

            var clients = await client.Clients.GetListAsync(userKey, null, null, ClientsSortBy.CompanyName, SortDirection.Ascending, null, null, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"All clients retrieved. Count = {clients.Count()}").ConfigureAwait(false);

            var updated = await client.Clients.UpdateAsync(userKey, registrationInfo.ClientId, name : "Fictitious Company").ConfigureAwait(false);

            await log.WriteLineAsync($"Client updated: {(updated ? "success" : "failed")}").ConfigureAwait(false);

            var myClient = await client.Clients.GetAsync(userKey, registrationInfo.ClientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Client retrieved: Name = {myClient.Name}").ConfigureAwait(false);

            var suspended = await client.Clients.SuspendAsync(userKey, myClient.Id).ConfigureAwait(false);

            await log.WriteLineAsync($"Client suspended: {(suspended ? "success" : "failed")}").ConfigureAwait(false);

            var reactivated = await client.Clients.ActivateAsync(userKey, myClient.Id).ConfigureAwait(false);

            await log.WriteLineAsync($"Client re-activated: {(reactivated ? "success" : "failed")}").ConfigureAwait(false);

            var deleted = await client.Clients.DeleteAsync(userKey, myClient.Id).ConfigureAwait(false);

            await log.WriteLineAsync($"Client deleted: {(deleted ? "success" : "failed")}").ConfigureAwait(false);
        }
示例#9
0
		public static async Task ExecuteAllMethods(ICakeMailRestClient client, string userKey, long clientId, TextWriter log, CancellationToken cancellationToken)
		{
			await log.WriteLineAsync("\n***** CAMPAIGNS *****").ConfigureAwait(false);

			var campaigns = await client.Campaigns.GetListAsync(userKey, CampaignStatus.Ongoing, null, CampaignsSortBy.Name, SortDirection.Ascending, null, null, clientId).ConfigureAwait(false);
			await log.WriteLineAsync($"All campaigns retrieved. Count = {campaigns.Count()}").ConfigureAwait(false);

			var campaignsCount = await client.Campaigns.GetCountAsync(userKey, CampaignStatus.Ongoing, null, clientId).ConfigureAwait(false);
			await log.WriteLineAsync($"Campaigns count = {campaignsCount}").ConfigureAwait(false);

			var campaignId = await client.Campaigns.CreateAsync(userKey, "Dummy campaign", clientId).ConfigureAwait(false);
			await log.WriteLineAsync($"New campaign created. Id: {campaignId}").ConfigureAwait(false);

			var updated = await client.Campaigns.UpdateAsync(userKey, campaignId, CampaignStatus.Ongoing, "Updated name", clientId).ConfigureAwait(false);
			await log.WriteLineAsync($"Campaign updated: {(updated ? "success" : "failed")}").ConfigureAwait(false);

			var campaign = await client.Campaigns.GetAsync(userKey, campaignId, clientId).ConfigureAwait(false);
			await log.WriteLineAsync($"Campaign retrieved: Name = {campaign.Name}").ConfigureAwait(false);

			var deleted = await client.Campaigns.DeleteAsync(userKey, campaignId, clientId).ConfigureAwait(false);
			await log.WriteLineAsync($"Campaign deleted: {(deleted ? "success" : "failed")}").ConfigureAwait(false);
		}
示例#10
0
        public static async Task ExecuteAllMethods(ICakeMailRestClient client, string userKey, long clientId, TextWriter log, CancellationToken cancellationToken)
        {
            await log.WriteLineAsync("\n***** TRIGGERS *****").ConfigureAwait(false);

            var listId = await client.Lists.CreateAsync(userKey, "INTEGRATION TESTING list for trigger", "Bob Smith", "*****@*****.**", true, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"New list created. Id: {listId}").ConfigureAwait(false);

            var listMemberId = await client.Lists.SubscribeAsync(userKey, listId, "*****@*****.**", true, true, null, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"New member subscribed to the list. Id: {listMemberId}").ConfigureAwait(false);

            var campaignId = await client.Campaigns.CreateAsync(userKey, "INTEGRATION TESTING campaign for trigger", clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"New campaign created. Id: {campaignId}").ConfigureAwait(false);

            var triggers = await client.Triggers.GetTriggersAsync(userKey, TriggerStatus.Active, null, null, null, null, null, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Active triggers retrieved. Count = {triggers.Count()}").ConfigureAwait(false);

            var triggersCount = await client.Triggers.GetCountAsync(userKey, TriggerStatus.Active, null, null, null, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Active triggers count = {triggersCount}").ConfigureAwait(false);

            var triggerId = await client.Triggers.CreateAsync(userKey, "Integration Testing: trigger", listId, campaignId, null, null, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"New trigger created. Id: {triggerId}").ConfigureAwait(false);

            var trigger = await client.Triggers.GetAsync(userKey, triggerId, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Trigger retrieved: Name = {trigger.Name}").ConfigureAwait(false);

            var updated = await client.Triggers.UpdateAsync(userKey, triggerId, name : "UPDATED INTEGRATION TEST: trigger", htmlContent : "<html><body>Hello World in HTML. <a href=\"http://cakemail.com\">CakeMail web site</a></body></html>", textContent : "Hello World in text", subject : "This is a test", trackClicksInHtml : true, trackClicksInText : true, trackOpens : true, clientId : clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Trigger updated: {(updated ? "success" : "failed")}").ConfigureAwait(false);

            var rawEmail = await client.Triggers.GetRawEmailMessageAsync(userKey, triggerId, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Trigger raw email: {rawEmail.Message}").ConfigureAwait(false);

            var rawHtml = await client.Triggers.GetRawHtmlAsync(userKey, triggerId, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Trigger raw html: {rawHtml}").ConfigureAwait(false);

            var rawText = await client.Triggers.GetRawTextAsync(userKey, triggerId, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Trigger raw text: {rawText}").ConfigureAwait(false);

            var unleashed = await client.Triggers.UnleashAsync(userKey, triggerId, listMemberId, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Trigger unleashed: {(unleashed ? "success" : "failed")}").ConfigureAwait(false);

            // Short pause to allow CakeMail to send the trigger
            await Task.Delay(2000).ConfigureAwait(false);

            var logs = await client.Triggers.GetLogsAsync(userKey, triggerId, null, null, false, false, null, null, null, null, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Trigger logs retrieved. Count = {logs.Count()}").ConfigureAwait(false);

            var links = await client.Triggers.GetLinksAsync(userKey, triggerId, 0, 0, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Trigger links retrieved. Count = {links.Count()}").ConfigureAwait(false);

            var linksCount = await client.Triggers.GetLinksCountAsync(userKey, triggerId, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Trigger links count = {linksCount}").ConfigureAwait(false);

            var linksStats = await client.Triggers.GetLinksWithStatsAsync(userKey, triggerId, null, null, null, null, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Trigger links stats retrieved. Count = {linksStats.Count()}").ConfigureAwait(false);

            var linksStatsCount = await client.Triggers.GetLinksWithStatsCountAsync(userKey, triggerId, null, null, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Trigger links stats count = {linksStatsCount}").ConfigureAwait(false);

            if (links.Any())
            {
                // As of May 2015, CakeMail has not implemented despite documenting in on their web site
                //var link = client.Triggers.GetLink(userKey, links.First().Id, clientId);
                //await log.WriteLineAsync($"Trigger link retrieved. URI = {0}", link.Uri).ConfigureAwait(false);
            }

            var listDeleted = await client.Lists.DeleteAsync(userKey, listId, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"List deleted: {(listDeleted ? "success" : "failed")}").ConfigureAwait(false);

            var campaignDeleted = await client.Campaigns.DeleteAsync(userKey, campaignId, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"List deleted: {(campaignDeleted ? "success" : "failed")}").ConfigureAwait(false);
        }
示例#11
0
        public static async Task ExecuteAllMethods(ICakeMailRestClient client, string userKey, long clientId, TextWriter log, CancellationToken cancellationToken)
        {
            await log.WriteLineAsync("\n***** TEMPLATES *****").ConfigureAwait(false);

            var categoryLabels = new Dictionary <string, string>
            {
                { "en_US", "My Category" },
                { "fr_FR", "Ma Catégorie" }
            };
            var categoryId = await client.Templates.CreateCategoryAsync(userKey, categoryLabels, true, true, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"New template category created. Id: {categoryId}").ConfigureAwait(false);

            var category = await client.Templates.GetCategoryAsync(userKey, categoryId, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Template category retrieved: Name = {category.Name}").ConfigureAwait(false);

            categoryLabels = new Dictionary <string, string>
            {
                { "en_US", "My Category UPDATED" },
                { "fr_FR", "Ma Catégorie UPDATED" }
            };
            var categoryUpdated = await client.Templates.UpdateCategoryAsync(userKey, categoryId, categoryLabels, true, true, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Template category updated. Id: {categoryId}").ConfigureAwait(false);

            var categories = await client.Templates.GetCategoriesAsync(userKey, 0, 0, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"All Template categories retrieved. Count = {categories.Count()}").ConfigureAwait(false);

            var categoriesCount = await client.Templates.GetCategoriesCountAsync(userKey, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Template categories count = {categoriesCount}").ConfigureAwait(false);

            var permissions = await client.Templates.GetCategoryVisibilityAsync(userKey, categoryId, null, null, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Template category permissions: {string.Join(", ", permissions.Select(p => string.Format("{0}={1}", p.CompanyName, p.Visible)))}").ConfigureAwait(false);

            if (permissions.Any())
            {
                var newPermissions     = permissions.ToDictionary(p => p.ClientId, p => false);
                var permissionsRevoked = await client.Templates.SetCategoryVisibilityAsync(userKey, categoryId, newPermissions, clientId).ConfigureAwait(false);

                await log.WriteLineAsync($"Template category permissions revoked: {(permissionsRevoked ? "success" : "failed")}").ConfigureAwait(false);
            }

            var templateLabels = new Dictionary <string, string>
            {
                { "en_US", "My Template" },
                { "fr_FR", "Mon Modèle" }
            };
            var templateContent = "<html><body>Hello World</body></html>";
            var templateId      = await client.Templates.CreateAsync(userKey, templateLabels, templateContent, categoryId, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Template created. Id = {templateId}").ConfigureAwait(false);

            templateLabels = new Dictionary <string, string>
            {
                { "en_US", "My Template UPDATED" },
                { "fr_FR", "Ma Modèle UPDATED" }
            };
            var templateUpdated = await client.Templates.UpdateAsync(userKey, templateId, templateLabels, templateContent, categoryId, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Template updated. Id: {templateId}").ConfigureAwait(false);

            var templates = await client.Templates.GetTemplatesAsync(userKey, categoryId, null, null, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"All Templates retrieved. Count = {templates.Count()}").ConfigureAwait(false);

            var template = await client.Templates.GetAsync(userKey, templateId, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Template retrieved: Name = {template.Name}").ConfigureAwait(false);

            var templateDeleted = await client.Templates.DeleteAsync(userKey, templateId, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Template deleted: {(templateDeleted ? "success" : "failed")}").ConfigureAwait(false);

            var categoryDeleted = await client.Templates.DeleteCategoryAsync(userKey, categoryId, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Template category deleted: {(categoryDeleted ? "success" : "failed")}").ConfigureAwait(false);
        }
示例#12
0
        public static async Task ExecuteAllMethods(ICakeMailRestClient client, string userKey, long clientId, TextWriter log, CancellationToken cancellationToken)
        {
            await log.WriteLineAsync("\n***** LISTS *****").ConfigureAwait(false);

            var lists = await client.Lists.GetListsAsync(userKey, ListStatus.Active, null, ListsSortBy.Name, SortDirection.Descending, null, null, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"All lists retrieved. Count = {lists.Count()}").ConfigureAwait(false);

            var listsCount = await client.Lists.GetCountAsync(userKey, ListStatus.Active, null, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Lists count = {listsCount}").ConfigureAwait(false);

            var listId = await client.Lists.CreateAsync(userKey, "Dummy list", "Bob Smith", "*****@*****.**", true, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"New list created. Id: {listId}").ConfigureAwait(false);

            var updated = await client.Lists.UpdateAsync(userKey, listId, name : "Updated name", clientId : clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"List updated: {(updated ? "success" : "failed")}").ConfigureAwait(false);

            var list = await client.Lists.GetAsync(userKey, listId, false, false, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"List retrieved: Name = {list.Name}").ConfigureAwait(false);

            await client.Lists.AddFieldAsync(userKey, listId, "MyCustomField1", FieldType.Integer, clientId).ConfigureAwait(false);

            await client.Lists.AddFieldAsync(userKey, listId, "MyCustomField2", FieldType.DateTime, clientId).ConfigureAwait(false);

            await client.Lists.AddFieldAsync(userKey, listId, "MyCustomField3", FieldType.Text, clientId).ConfigureAwait(false);

            await client.Lists.AddFieldAsync(userKey, listId, "MyCustomField4", FieldType.Memo, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Custom fields added to the list").ConfigureAwait(false);

            var fields = await client.Lists.GetFieldsAsync(userKey, listId, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"List contains the following fields: {string.Join(", ", fields.Select(f => f.Name))}").ConfigureAwait(false);

            var subscriberCustomFields = new Dictionary <string, object>()
            {
                { "MyCustomField1", 12345 },
                { "MyCustomField2", DateTime.UtcNow },
                { "MyCustomField3", "qwerty" }
            };
            var listMemberId = await client.Lists.SubscribeAsync(userKey, listId, "*****@*****.**", true, true, subscriberCustomFields, clientId).ConfigureAwait(false);

            await log.WriteLineAsync("One member added to the list").ConfigureAwait(false);

            var query       = "`email`=\"[email protected]\"";
            var subscribers = await client.Lists.GetMembersAsync(userKey, listId, query : query, clientId : clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Subscribers retrieved: {subscribers.Count()}").ConfigureAwait(false);

            var subscriber = await client.Lists.GetMemberAsync(userKey, listId, listMemberId, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Subscriber retrieved: {subscriber.Email}").ConfigureAwait(false);

            var member1 = new ListMember
            {
                Email        = "*****@*****.**",
                CustomFields = new Dictionary <string, object>
                {
                    { "MyCustomField1", 12345 },
                    { "MyCustomField2", DateTime.UtcNow },
                    { "MyCustomField3", "qwerty" }
                }
            };
            var member2 = new ListMember
            {
                Email        = "*****@*****.**",
                CustomFields = new Dictionary <string, object>
                {
                    { "MyCustomField1", 98765 },
                    { "MyCustomField2", DateTime.MinValue },
                    { "MyCustomField3", "azerty" }
                }
            };
            var importResult = await client.Lists.ImportAsync(userKey, listId, new[] { member1, member2 }, false, false, clientId).ConfigureAwait(false);

            await log.WriteLineAsync("Two members imported into the list").ConfigureAwait(false);

            var members = await client.Lists.GetMembersAsync(userKey, listId, null, null, null, null, null, null, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"All list members retrieved. Count = {members.Count()}").ConfigureAwait(false);

            var membersCount = await client.Lists.GetMembersCountAsync(userKey, listId, null, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Members count = {membersCount}").ConfigureAwait(false);

            var customFieldsToUpdate = new Dictionary <string, object>
            {
                { "MyCustomField1", 555555 },
                { "MyCustomField3", "zzzzzzzzzzzzzzzzzzzzzzzzzz" }
            };
            var memberUpdated = await client.Lists.UpdateMemberAsync(userKey, listId, 1, customFieldsToUpdate, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Member updated: {(memberUpdated ? "success" : "failed")}").ConfigureAwait(false);

            var logs = await client.Lists.GetLogsAsync(userKey, listId, LogType.Open, false, false, null, null, null, null, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Retrieved 'Opens'. Count = {logs.Count()}").ConfigureAwait(false);

            var firstSegmentId = await client.Segments.CreateAsync(userKey, listId, "Segment #1", "(`email` LIKE \"aa%\")", clientId).ConfigureAwait(false);

            var secondSegmentId = await client.Segments.CreateAsync(userKey, listId, "Segment #2", "(`email` LIKE \"bb%\")", clientId).ConfigureAwait(false);

            await log.WriteLineAsync("Two segments created").ConfigureAwait(false);

            var segments = await client.Segments.GetSegmentsAsync(userKey, listId, 0, 0, true, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Segments retrieved. Count = {segments.Count()}").ConfigureAwait(false);

            var firstSegmentDeleted = await client.Segments.DeleteAsync(userKey, firstSegmentId, clientId).ConfigureAwait(false);

            await log.WriteLineAsync("First segment deleted").ConfigureAwait(false);

            var secondSegmentDeleted = await client.Segments.DeleteAsync(userKey, secondSegmentId, clientId).ConfigureAwait(false);

            await log.WriteLineAsync("Second segment deleted").ConfigureAwait(false);

            var deleted = await client.Lists.DeleteAsync(userKey, listId, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"List deleted: {(deleted ? "success" : "failed")}").ConfigureAwait(false);
        }
        public static async Task ExecuteAllMethods(ICakeMailRestClient client, string userKey, long clientId, TextWriter log, CancellationToken cancellationToken)
        {
            await log.WriteLineAsync("\n***** MAILINGS *****").ConfigureAwait(false);

            var mailings = await client.Mailings.GetMailingsAsync(userKey, null, MailingType.Standard, null, null, null, null, null, null, MailingsSortBy.Name, SortDirection.Descending, null, null, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"All mailings retrieved. Count = {mailings.Count()}").ConfigureAwait(false);

            var mailingsCount = await client.Mailings.GetCountAsync(userKey, null, MailingType.Standard, null, null, null, null, null, null, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Mailings count = {mailingsCount}").ConfigureAwait(false);

            var mailingId = await client.Mailings.CreateAsync(userKey, "Integration Testing", clientId : clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"New mailing created. Id: {mailingId}").ConfigureAwait(false);

            var lists = await client.Lists.GetListsAsync(userKey, ListStatus.Active, null, ListsSortBy.Name, SortDirection.Descending, 1, 0, clientId).ConfigureAwait(false);

            var list    = lists.First();
            var updated = await client.Mailings.UpdateAsync(userKey, mailingId, name : "UPDATED Integration Test", listId : list.Id, htmlContent : "<html><body>Hello World in HTML.  <a href=\"http://cakemail.com\">CakeMail web site</a></body></html>", textContent : "Hello World in text", subject : "This is a test", clientId : clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Mailing updated: {(updated ? "success" : "failed")}").ConfigureAwait(false);

            var mailing = await client.Mailings.GetAsync(userKey, mailingId, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Mailing retrieved: Name = {mailing.Name}").ConfigureAwait(false);

            var testSent = await client.Mailings.SendTestEmailAsync(userKey, mailingId, "*****@*****.**", true, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Test sent: {(testSent ? "success" : "failed")}").ConfigureAwait(false);

            var rawEmail = await client.Mailings.GetRawEmailMessageAsync(userKey, mailingId, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Mailing raw email: {rawEmail.Message}").ConfigureAwait(false);

            var rawHtml = await client.Mailings.GetRawHtmlAsync(userKey, mailingId, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Mailing raw html: {rawHtml}").ConfigureAwait(false);

            var rawText = await client.Mailings.GetRawTextAsync(userKey, mailingId, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Mailing raw text: {rawText}").ConfigureAwait(false);

            var scheduled = await client.Mailings.ScheduleAsync(userKey, mailingId, DateTime.UtcNow.AddDays(2), clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Mailing scheduled: {(scheduled ? "success" : "failed")}").ConfigureAwait(false);

            var unscheduled = await client.Mailings.UnscheduleAsync(userKey, mailingId, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Mailing unscheduled: {(unscheduled ? "success" : "failed")}").ConfigureAwait(false);

            var deleted = await client.Mailings.DeleteAsync(userKey, mailingId, clientId).ConfigureAwait(false);

            await log.WriteLineAsync($"Mailing deleted: {(deleted ? "success" : "failed")}").ConfigureAwait(false);

            var sentMailings = mailings.Where(m => m.Status == MailingStatus.Delivered);

            if (sentMailings.Any())
            {
                var sentMailingId = sentMailings.First().Id;

                var logs = await client.Mailings.GetLogsAsync(userKey, sentMailingId, null, null, false, false, null, null, 25, 0, clientId).ConfigureAwait(false);

                await log.WriteLineAsync($"Mailing logs retrieved. Count = {logs.Count()}").ConfigureAwait(false);

                var links = await client.Mailings.GetLinksAsync(userKey, sentMailingId, null, null, clientId).ConfigureAwait(false);

                await log.WriteLineAsync($"Mailing links retrieved. Count = {links.Count()}").ConfigureAwait(false);

                var linksCount = await client.Mailings.GetLinksCountAsync(userKey, sentMailingId, clientId).ConfigureAwait(false);

                await log.WriteLineAsync($"Mailing links count = {linksCount}").ConfigureAwait(false);

                var linksStats = await client.Mailings.GetLinksWithStatsAsync(userKey, sentMailingId, null, null, null, null, clientId).ConfigureAwait(false);

                await log.WriteLineAsync($"Mailing links stats retrieved. Count = {linksStats}").ConfigureAwait(false);

                var linksStatsCount = await client.Mailings.GetLinksWithStatsCountAsync(userKey, sentMailingId, null, null, null, null, clientId).ConfigureAwait(false);

                await log.WriteLineAsync($"Mailing links stats count = {linksStatsCount}").ConfigureAwait(false);
            }
        }