Ejemplo n.º 1
0
        public void Should_Generate_NewPost_EmailContent(int retries)
        {
            var mailTemplate = new MailTemplate();

            var newWallPostEmailTemplateViewModel = new NewWallPostEmailTemplateViewModel(
                "WallTitle",
                "http://picture.example.com",
                "Iam Creator",
                "http://post.example.com/1",
                "body",
                "http://settings.example.com/1",
                "Read it");

            var kudosSentEmailTemplateViewModel = new KudosSentEmailTemplateViewModel(
                "http://settings.example.com/1",
                "Iam Creator",
                10,
                "New kudos for you!",
                "http://profile.example.com/1");

            for (var i = 0; i < retries; i++)
            {
                TestContext.Progress.WriteLine($"Generating {i + 1}/{retries}");

                mailTemplate.Generate(newWallPostEmailTemplateViewModel, EmailTemplateCacheKeys.NewWallPost);
                mailTemplate.Generate(kudosSentEmailTemplateViewModel, EmailTemplateCacheKeys.KudosSent);
            }
        }
        public async Task NotifyAboutKudosSentAsync(AddKudosDto kudosDto)
        {
            var organizationName = (await GetOrganizationNameAsync(kudosDto.KudosLog.OrganizationId)).ShortName;

            var recipient = _usersDbSet
                            .Where(u => kudosDto.ReceivingUser.Id.Contains(u.Id))
                            .Select(u => u.Email);

            var userNotificationSettingsUrl = _appSettings.UserNotificationSettingsUrl(organizationName);
            var kudosProfileUrl             = _appSettings.KudosProfileUrl(organizationName, kudosDto.ReceivingUser.Id);
            var subject = Resources.Models.Kudos.Kudos.EmailSubject;

            var emailTemplateViewModel = new KudosSentEmailTemplateViewModel(userNotificationSettingsUrl,
                                                                             kudosDto.SendingUser.FullName,
                                                                             kudosDto.TotalKudosPointsInLog,
                                                                             kudosDto.KudosLog.Comment,
                                                                             kudosProfileUrl);

            var body = _mailTemplate.Generate(emailTemplateViewModel, EmailTemplateCacheKeys.KudosSent);
            await _mailingService.SendEmailAsync(new EmailDto(recipient, subject, body));
        }