Exemplo n.º 1
0
        /// <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);
        }
        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);
        }