private async Task <NotificationReportResponse> GetNotificationReportTest(string notificationId, HttpClient httpClient) { NotificationReportResponse reportResponse = null; var reqcontent = "{\"applicationFilter\":[\"" + this.Configuration[FunctionalConstants.Application] + "\"], \"notificationIdsFilter\":[\"" + notificationId + "\"] }"; var stringContent = new StringContent(reqcontent, Encoding.UTF8, FunctionalConstants.ContentType); string notificationReportEndpoint = $"{this.Configuration[FunctionalConstants.NotificationHandlerUrl]}/v1/report/notifications"; var response = await httpClient.PostAsync(notificationReportEndpoint, stringContent).ConfigureAwait(false); if (!response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); Assert.Fail(); } else { var Result = response.Content.ReadAsStringAsync().Result; IList <NotificationReportResponse> reportResponses = JsonConvert.DeserializeObject <IList <NotificationReportResponse> >(Result); reportResponse = reportResponses.FirstOrDefault(); } return(reportResponse); }
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(); } } }