public async Task <IActionResult> ReadNotificationsStatusAsync(string applicationName, [FromBody] NotificationTrackingIdsContainer notificationTrackingIdsContainer) { IActionResult result = null; using (this.logger.BeginScope($"RootActivityId: {this.RootActivityId}")) { this.logger.LogInformation($"Started {nameof(this.ReadNotificationsStatusAsync)} method of {nameof(NotificationsController)}."); if (string.IsNullOrWhiteSpace(applicationName)) { throw new ArgumentException("Application name is mandatory.", nameof(applicationName)); } if (notificationTrackingIdsContainer == null) { throw new ArgumentNullException(nameof(notificationTrackingIdsContainer)); } WebNotificationStatusResponse statusResponse = await this.notificationsManager.LoadNotificationStatusAsync(applicationName, notificationTrackingIdsContainer.TrackingIds).ConfigureAwait(false); result = this.Ok(statusResponse); this.logger.LogInformation($"Finished {nameof(this.ReadNotificationsStatusAsync)} method of {nameof(NotificationsController)}."); } return(result); }
/// <summary> /// Prepares the notification status response. /// </summary> /// <param name="trackingIds">The tracking ids.</param> /// <param name="webNotificationItemEntities">The web notification item entities.</param> /// <returns>The instance of <see cref="WebNotificationStatusResponse"/>.</returns> private static WebNotificationStatusResponse PrepareNotificationStatusResponse(IEnumerable <string> trackingIds, IEnumerable <WebNotificationItemEntity> webNotificationItemEntities) { Debug.Assert(trackingIds?.Any() ?? false, "Missing tracking Ids"); WebNotificationStatus webNotificationStatus; WebNotificationStatusResponse statusResponse = new WebNotificationStatusResponse(); IEnumerable <string> absentTrackingIds = LocateAbsentTrackingIds(trackingIds, webNotificationItemEntities); foreach (WebNotificationItemEntity webNotificationEntity in webNotificationItemEntities) { webNotificationStatus = new WebNotificationStatus { TrackingId = webNotificationEntity.TrackingId, IsValidTrackingId = true, NotificationId = webNotificationEntity.NotificationId, ReadStatus = webNotificationEntity.ReadStatus, }; webNotificationStatus.DeliveryStatus[NotificationDeliveryChannel.Web.ToString().ToLowerInvariant()] = webNotificationEntity.DeliveredOnChannel[NotificationDeliveryChannel.Web]; statusResponse.NotificationStatus.Add(webNotificationStatus); } foreach (string absentTrackingId in absentTrackingIds) { webNotificationStatus = new WebNotificationStatus { IsValidTrackingId = false, TrackingId = absentTrackingId, }; statusResponse.NotificationStatus.Add(webNotificationStatus); } return(statusResponse); }
/// <inheritdoc cref="INotificationsManager"/> public async Task <WebNotificationStatusResponse> LoadNotificationStatusAsync(string applicationName, IEnumerable <string> trackingIds) { this.logger.TraceInformation($"Started {nameof(this.LoadNotificationStatusAsync)} method of {nameof(NotificationsManager)}."); if (string.IsNullOrWhiteSpace(applicationName)) { throw new ArgumentException("The application name is not specified.", nameof(applicationName)); } if (!(trackingIds?.Any() ?? false)) { throw new ArgumentException("There are no tracking Ids.", nameof(trackingIds)); } EntityCollection <WebNotificationItemEntity> webNotificationsCollection = await this.LoadNotificationsWithIdsInternalAsync(trackingIds, applicationName, isTrackingIds : true).ConfigureAwait(false); WebNotificationStatusResponse statusResponse = PrepareNotificationStatusResponse(trackingIds, webNotificationsCollection.Items); this.logger.TraceInformation($"Finished {nameof(this.LoadNotificationStatusAsync)} method of {nameof(NotificationsManager)}."); return(statusResponse); }
public async Task ReadNotificationsStatusAsync_ValidInputs() { NotificationTrackingIdsContainer notificationTrackingIdsContainer = new NotificationTrackingIdsContainer(); string trackingId = Guid.NewGuid().ToString(); WebNotificationStatusResponse response = new WebNotificationStatusResponse(); WebNotificationStatus notificationStatus = new WebNotificationStatus { NotificationId = Guid.NewGuid().ToString(), TrackingId = trackingId, ReadStatus = NotificationReadStatus.New, IsValidTrackingId = true, }; notificationStatus.DeliveryStatus.Add("Web", true); response.NotificationStatus.Add(notificationStatus); _ = this.NotificationsManagerMock.Setup(nm => nm.LoadNotificationStatusAsync(It.IsAny <string>(), It.IsAny <IEnumerable <string> >())).Returns(Task.FromResult(response)); var statusResponse = await this.NotificationsControllerObject.ReadNotificationsStatusAsync(this.ApplicationName, notificationTrackingIdsContainer).ConfigureAwait(false); Assert.IsTrue(statusResponse.GetType().FullName.Equals(typeof(OkObjectResult).FullName, StringComparison.Ordinal)); this.NotificationsManagerMock.Verify(nm => nm.LoadNotificationStatusAsync(It.IsAny <string>(), It.IsAny <IEnumerable <string> >()), Times.Once); }