/// <summary>
        /// Converts <see cref="EmailNotificationItemTableEntity"/> to a <see cref="EmailNotificationItemEntity"/>.
        /// </summary>
        /// <param name="emailNotificationItemTableEntity"> EmailNotificationItemTableEntity. </param>
        /// <returns><see cref="EmailNotificationItemEntity"/>.</returns>
        public static EmailNotificationItemEntity ConvertToEmailNotificationItemEntity(this EmailNotificationItemTableEntity emailNotificationItemTableEntity)
        {
            if (emailNotificationItemTableEntity is null)
            {
                return(null);
            }

            EmailNotificationItemEntity emailNotificationItemEntity = new EmailNotificationItemEntity();
            NotificationPriority        notificationPriority        = Enum.TryParse <NotificationPriority>(emailNotificationItemTableEntity.Priority, out notificationPriority) ? notificationPriority : NotificationPriority.Low;
            NotificationItemStatus      notificationItemStatus      = Enum.TryParse <NotificationItemStatus>(emailNotificationItemTableEntity.Status, out notificationItemStatus) ? notificationItemStatus : NotificationItemStatus.Queued;

            emailNotificationItemEntity.Priority         = notificationPriority;
            emailNotificationItemEntity.Status           = notificationItemStatus;
            emailNotificationItemEntity.PartitionKey     = emailNotificationItemTableEntity.Application;
            emailNotificationItemEntity.RowKey           = emailNotificationItemTableEntity.NotificationId;
            emailNotificationItemEntity.Application      = emailNotificationItemTableEntity.Application;
            emailNotificationItemEntity.BCC              = emailNotificationItemTableEntity.BCC;
            emailNotificationItemEntity.CC               = emailNotificationItemTableEntity.CC;
            emailNotificationItemEntity.EmailAccountUsed = emailNotificationItemTableEntity.EmailAccountUsed;
            emailNotificationItemEntity.ErrorMessage     = emailNotificationItemTableEntity.ErrorMessage;
            emailNotificationItemEntity.From             = emailNotificationItemTableEntity.From;
            emailNotificationItemEntity.NotificationId   = emailNotificationItemTableEntity.NotificationId;
            emailNotificationItemEntity.ReplyTo          = emailNotificationItemTableEntity.ReplyTo;
            emailNotificationItemEntity.Sensitivity      = emailNotificationItemTableEntity.Sensitivity;
            emailNotificationItemEntity.Subject          = emailNotificationItemTableEntity.Subject;
            emailNotificationItemEntity.TemplateId       = emailNotificationItemTableEntity.TemplateId;
            //emailNotificationItemEntity.TemplateData = emailNotificationItemTableEntity.TemplateData;
            emailNotificationItemEntity.Timestamp     = emailNotificationItemTableEntity.Timestamp;
            emailNotificationItemEntity.To            = emailNotificationItemTableEntity.To;
            emailNotificationItemEntity.TrackingId    = emailNotificationItemTableEntity.TrackingId;
            emailNotificationItemEntity.TryCount      = emailNotificationItemTableEntity.TryCount;
            emailNotificationItemEntity.ETag          = emailNotificationItemTableEntity.ETag;
            emailNotificationItemEntity.SendOnUtcDate = emailNotificationItemTableEntity.SendOnUtcDate;
            return(emailNotificationItemEntity);
        }
Пример #2
0
        private IList <MeetingNotificationItemEntity> GetMeetingNotificationItems(NotificationItemStatus status)
        {
            var notificationId2 = Guid.NewGuid().ToString();
            var date            = DateTime.UtcNow;

            return(new List <MeetingNotificationItemEntity>()
            {
                new MeetingNotificationItemEntity()
                {
                    Application = this.ApplicationName,
                    NotificationId = notificationId2,
                    Subject = "TestEmailSubject",
                    Body = "CfDJ8KvR5DP4DK5GqV1jviPzBnsv3onVDZ-ztz-AvRl_6nvVNg86jfmKjgySREDPW9xNrwpKALT5BIFNX6VK3wzKsxc51dbkQjPPG9l7436wQktrAMRadumTpGKNKG1lLlP0FA",
                    Id = notificationId2,
                    Status = status,
                    RequiredAttendees = "*****@*****.**",
                    Start = date,
                    End = date.AddHours(1),
                    Priority = NotificationPriority.Normal,
                    Location = "Test",
                },
            });
        }
Пример #3
0
        private async Task UpdateStatusOfNotificationItemsAsync(string[] notificationIds, NotificationItemStatus status, string errorMessage)
        {
            this.logger.TraceInformation($"UpdateStatusOfNotificationItemsAsync started. Notification Ids: {notificationIds}");
            try
            {
                IList <EmailNotificationItemEntity> notificationEntities = await this.emailNotificationRepository.GetEmailNotificationItemEntities(new List <string>(notificationIds)).ConfigureAwait(false);

                if (notificationEntities.Count == 0)
                {
                    this.logger.WriteException(new ArgumentException("No records found for the input notification ids.", nameof(notificationIds)));
                }

                foreach (var item in notificationEntities)
                {
                    item.Status       = status;
                    item.ErrorMessage = errorMessage;
                }

                // Update the status of processed entities
                await this.emailNotificationRepository.UpdateEmailNotificationItemEntities(notificationEntities).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                this.logger.WriteException(ex);
            }

            this.logger.TraceInformation($"UpdateStatusOfNotificationItemsAsync finished.");
        }
        /// <inheritdoc/>
        public async Task <IList <MeetingNotificationItemEntity> > CreateMeetingNotificationEntities(string applicationName, MeetingNotificationItem[] meetingNotificationItems, NotificationItemStatus status)
        {
            if (meetingNotificationItems is null)
            {
                throw new ArgumentNullException(nameof(meetingNotificationItems));
            }

            var traceProps = new Dictionary <string, string>();

            traceProps[Constants.Application] = applicationName;

            this.logger.TraceInformation($"Started {nameof(this.CreateNotificationEntities)} method of {nameof(EmailManager)}.", traceProps);
            IList <MeetingNotificationItemEntity> notificationEntities = new List <MeetingNotificationItemEntity>();

            foreach (var item in meetingNotificationItems)
            {
                var notificationEntity = item.ToEntity(applicationName);
                notificationEntity.NotificationId  = !string.IsNullOrWhiteSpace(item.NotificationId) ? item.NotificationId : Guid.NewGuid().ToString();
                notificationEntity.Id              = Guid.NewGuid().ToString();
                notificationEntity.CreatedDateTime = DateTime.UtcNow;
                notificationEntity.UpdatedDateTime = DateTime.UtcNow;
                notificationEntity.Status          = status;
                notificationEntities.Add(notificationEntity);
            }

            await this.emailNotificationRepository.CreateMeetingNotificationItemEntities(notificationEntities, applicationName).ConfigureAwait(false);

            this.logger.TraceInformation($"Completed {nameof(this.CreateNotificationEntities)} method of {nameof(EmailManager)}.", traceProps);
            return(notificationEntities);
        }
Пример #5
0
        public async Task QueueEmailGetNotificationMessageGetNotificationReportTest()
        {
            var emailNotificationItems = new EmailNotificationItem[]
            {
                new EmailNotificationItem()
                {
                    To      = Configuration[FunctionalConstants.ToAddress],
                    Subject = "Notification Functional Testing of Email Queue Endpoint",
                    Body    = "Hello world!"
                }
            };

            var    stringContent             = new StringContent(JsonConvert.SerializeObject(emailNotificationItems), Encoding.UTF8, FunctionalConstants.ContentType);
            string notificationQueueEndpoint = $"{this.Configuration[FunctionalConstants.NotificationHandlerUrl]}/v1/email/queue/{this.Configuration[FunctionalConstants.Application]}";

            using (HttpClient httpClient = new HttpClient())
            {
                string bearerToken = await this.tokenUtility.GetTokenAsync();

                if (bearerToken != null)
                {
                    httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(FunctionalConstants.Bearer, bearerToken);

                    var response = await httpClient.PostAsync(notificationQueueEndpoint, stringContent).ConfigureAwait(false);

                    if (!response.IsSuccessStatusCode)
                    {
                        var content = await response.Content.ReadAsStringAsync();

                        Assert.Fail();
                    }
                    else
                    {
                        var Result = response.Content.ReadAsStringAsync().Result;
                        var notificationResponses = JsonConvert.DeserializeObject <List <NotificationResponse> >(Result);
                        var notificationResponse  = notificationResponses.FirstOrDefault();
                        Assert.IsTrue(notificationResponse.Status == NotificationItemStatus.Queued);
                        var          notificationId = notificationResponse.NotificationId;
                        EmailMessage emailMessage   = await GetNotificationMessageTest(notificationId, httpClient);

                        if (emailMessage != null)
                        {
                            Assert.IsTrue(emailNotificationItems[0].Subject == emailMessage.Subject);
                            Assert.IsTrue(emailNotificationItems[0].Body == emailMessage.Body.Content);
                        }
                        else
                        {
                            Assert.Fail();
                        }

                        int retryCount = int.TryParse(Configuration[FunctionalConstants.RetryCount], out retryCount) ? retryCount : 2;
                        int delayTime  = int.TryParse(Configuration[FunctionalConstants.DelayTimeInMilliSeconds], out delayTime) ? delayTime : 5000;


                        for (int i = 0; i < retryCount; i++)
                        {
                            NotificationReportResponse notificationReportResponse = await GetNotificationReportTest(notificationId, httpClient);

                            if (notificationReportResponse != null)
                            {
                                NotificationItemStatus notificationItemStatus = Enum.TryParse <NotificationItemStatus>(notificationReportResponse.Status, out notificationItemStatus) ? notificationItemStatus : NotificationItemStatus.Queued;
                                switch (notificationItemStatus)
                                {
                                case NotificationItemStatus.Failed:
                                case NotificationItemStatus.FakeMail:
                                case NotificationItemStatus.Invalid:
                                {
                                    Assert.Fail();
                                    break;
                                }

                                case NotificationItemStatus.Sent:
                                {
                                    Assert.Pass();
                                    break;
                                }

                                case NotificationItemStatus.Queued:
                                case NotificationItemStatus.Processing:
                                case NotificationItemStatus.Retrying:
                                {
                                    if (i == retryCount - 1)
                                    {
                                        Assert.Fail();
                                        break;
                                    }
                                    await Task.Delay(delayTime);

                                    continue;
                                }
                                }
                            }
                            else
                            {
                                Assert.Fail();
                            }
                        }
                    }
                }
                else
                {
                    Assert.Fail();
                }
            }
        }
        /// <summary>
        /// Test meeting invite queue, meeting invite report and meeting invite message including body
        /// </summary>
        public async Task MeetingInvitesQueueReportMessageTest()
        {
            var date = DateTime.UtcNow;
            var meetingInviteItems = new MeetingNotificationItem[]
            {
                new MeetingNotificationItem()
                {
                    From = this.Configuration[FunctionalConstants.ToAddress],
                    RequiredAttendees = this.Configuration[FunctionalConstants.ToAddress],
                    Subject           = "Functional Testing of Meeting Invites Queue endpoint",
                    Body     = "Lets meet!",
                    Start    = date,
                    End      = date.AddHours(1),
                    Priority = NotificationPriority.Normal
                }
            };

            var    stringContent = new StringContent(JsonConvert.SerializeObject(meetingInviteItems), Encoding.UTF8, FunctionalConstants.ContentType);
            string meetingInviteQueueEndpoint = $"{this.Configuration[FunctionalConstants.NotificationHandlerUrl]}/v1/meetinginvite/queue/{this.Configuration[FunctionalConstants.Application]}";

            using (HttpClient httpClient = new HttpClient())
            {
                string bearerToken = await this.tokenUtility.GetTokenAsync();

                if (bearerToken != null)
                {
                    httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(FunctionalConstants.Bearer, bearerToken);

                    var response = await httpClient.PostAsync(meetingInviteQueueEndpoint, stringContent).ConfigureAwait(false);

                    if (!response.IsSuccessStatusCode)
                    {
                        var content = await response.Content.ReadAsStringAsync();

                        Assert.Fail();
                    }
                    else
                    {
                        var Result = response.Content.ReadAsStringAsync().Result;
                        var notificationResponses = JsonConvert.DeserializeObject <List <NotificationResponse> >(Result);
                        var notificationResponse  = notificationResponses.FirstOrDefault();
                        Assert.IsTrue(notificationResponse.Status == NotificationItemStatus.Queued);

                        var notificationId = notificationResponse.NotificationId;
                        MeetingInviteMessage inviteMessage = await GetMeetingNotificationMessage(notificationId, httpClient);

                        if (inviteMessage != null)
                        {
                            Assert.IsTrue(meetingInviteItems[0].Subject == inviteMessage.Subject);
                            Assert.IsTrue(meetingInviteItems[0].Body == inviteMessage.Body);
                        }
                        else
                        {
                            Assert.Fail();
                        }

                        int retryCount = int.TryParse(Configuration[FunctionalConstants.RetryCount], out retryCount) ? retryCount : 2;
                        int delayTime  = int.TryParse(Configuration[FunctionalConstants.DelayTimeInMilliSeconds], out delayTime) ? delayTime : 5000;


                        for (int i = 0; i < retryCount; i++)
                        {
                            MeetingInviteReportResponse inviteReportResponse = await GetMeetingInviteReportTest(notificationId, httpClient);

                            if (inviteReportResponse != null)
                            {
                                NotificationItemStatus notificationItemStatus = Enum.TryParse <NotificationItemStatus>(inviteReportResponse.Status, out notificationItemStatus) ? notificationItemStatus : NotificationItemStatus.Queued;
                                switch (notificationItemStatus)
                                {
                                case NotificationItemStatus.Failed:
                                case NotificationItemStatus.FakeMail:
                                case NotificationItemStatus.Invalid:
                                {
                                    Assert.Fail();
                                    break;
                                }

                                case NotificationItemStatus.Sent:
                                {
                                    Assert.Pass();
                                    break;
                                }

                                case NotificationItemStatus.Queued:
                                case NotificationItemStatus.Processing:
                                case NotificationItemStatus.Retrying:
                                {
                                    if (i == retryCount - 1)
                                    {
                                        Assert.Fail();
                                        break;
                                    }
                                    await Task.Delay(delayTime);

                                    continue;
                                }
                                }
                            }
                            else
                            {
                                Assert.Fail();
                            }
                        }
                    }
                }
                else
                {
                    Assert.Fail();
                }
            }
        }
        /// <summary>
        /// Creates the notification entity records in database with the input status.
        /// </summary>
        /// <param name="applicationName">Application associated with notification items.</param>
        /// <param name="emailNotificationItems">Array of notifications items to be created.</param>
        /// <param name="status">Status of the items to be created.</param>
        /// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns>
        public async Task <IList <EmailNotificationItemEntity> > CreateNotificationEntities(string applicationName, EmailNotificationItem[] emailNotificationItems, NotificationItemStatus status)
        {
            var traceProps = new Dictionary <string, string>();

            traceProps[AIConstants.Application]            = applicationName;
            traceProps[AIConstants.EmailNotificationCount] = emailNotificationItems?.Length.ToString(CultureInfo.InvariantCulture);

            this.logger.TraceInformation($"Started {nameof(this.CreateNotificationEntities)} method of {nameof(EmailManager)}.", traceProps);
            IList <EmailNotificationItemEntity> notificationEntities = new List <EmailNotificationItemEntity>();

            foreach (var item in emailNotificationItems)
            {
                var notificationEntity = item.ToEntity(applicationName);
                notificationEntity.NotificationId  = !string.IsNullOrWhiteSpace(item.NotificationId) ? item.NotificationId : Guid.NewGuid().ToString();
                notificationEntity.Id              = Guid.NewGuid().ToString();
                notificationEntity.CreatedDateTime = DateTime.UtcNow;
                notificationEntity.UpdatedDateTime = DateTime.UtcNow;
                notificationEntity.Status          = status;
                notificationEntities.Add(notificationEntity);
            }

            await this.emailNotificationRepository.CreateEmailNotificationItemEntities(notificationEntities, applicationName).ConfigureAwait(false);

            this.logger.TraceInformation($"Completed {nameof(this.CreateNotificationEntities)} method of {nameof(EmailManager)}.", traceProps);
            return(notificationEntities);
        }