Exemplo n.º 1
0
        /// <inheritdoc cref="INotificationsManager"/>
        public async Task <WebNotificationResponse> DeliverNotificationsAsync(string applicationName, string userObjectId)
        {
            if (string.IsNullOrWhiteSpace(applicationName))
            {
                throw new ArgumentException("The application name is not specified.", nameof(applicationName));
            }

            if (string.IsNullOrWhiteSpace(userObjectId))
            {
                throw new ArgumentException("The user object identifier is not specified.", nameof(userObjectId));
            }

            WebNotificationResponse webNotificationResponse = new WebNotificationResponse();

            this.logger.TraceInformation($"Started {nameof(this.DeliverNotificationsAsync)} method of {nameof(NotificationsManager)}.");
            Expression <Func <WebNotificationItemEntity, bool> > filterExpression       = NotificationsExpressionProvider.PrepareNotificationsFilter(applicationName, notificationReadStatus: null, userObjectId: userObjectId);
            EntityCollection <WebNotificationItemEntity>         notificationCollection =
                await this.notificationsRepository.ReadAsync(
                    filterExpression,
                    NotificationsExpressionProvider.NotificationsSortOrderExpression,
                    nextPageId : null,
                    numOfEntities : BusinessConstants.PageSize).ConfigureAwait(false);

            webNotificationResponse.Notifications.AddRange(notificationCollection.Items.Select(wbn => wbn.ToWebNotification()));
            if (webNotificationResponse.Notifications.Any())
            {
                await this.MarkNotificationsDeliveredInternalAsync(NotificationDeliveryChannel.Web, notificationCollection.Items).ConfigureAwait(false);
            }

            this.logger.TraceInformation($"Finished {nameof(this.DeliverNotificationsAsync)} method of {nameof(NotificationsManager)}.");
            return(webNotificationResponse);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetNotifications(string applicationName)
        {
            IActionResult           result = null;
            WebNotificationResponse notificationResponse = null;

            using (this.logger.BeginScope($"RootActivityId: {this.RootActivityId}"))
            {
                this.logger.LogInformation($"Started {nameof(this.GetNotifications)} method of {nameof(NotificationsController)}.");
                if (string.IsNullOrWhiteSpace(applicationName))
                {
                    throw new ArgumentException("Application name is mandatory.", nameof(applicationName));
                }

                notificationResponse = await this.notificationsManager.DeliverNotificationsAsync(applicationName, this.HttpContext.User.FindFirst(ClaimTypeConstants.ObjectIdentifier)?.Value).ConfigureAwait(false);

                result = this.Ok(notificationResponse);
                this.logger.LogInformation($"Finished {nameof(this.GetNotifications)} method of {nameof(NotificationsController)}.");
            }

            return(result);
        }
        public void GetNotifications_ValidApplicationName()
        {
            string notificationId            = Guid.NewGuid().ToString();
            WebNotificationResponse response = new WebNotificationResponse();

            response.Notifications.Add(new WebNotification
            {
                NotificationId = notificationId,
                Recipient      = new Person {
                    ObjectIdentifier = "test object identifier."
                },
                Title = "Test Title",
                Body  = "Test Body",
            });

            _ = this.NotificationsManagerMock.Setup(nm => nm.DeliverNotificationsAsync(It.IsAny <string>(), It.IsAny <string>())).Returns(Task.FromResult(response));
            var result = this.NotificationsControllerObject.GetNotifications(this.ApplicationName);

            Assert.IsTrue(result.Result.GetType().FullName.Equals(typeof(OkObjectResult).FullName, StringComparison.Ordinal));
            this.NotificationsManagerMock.Verify(nm => nm.DeliverNotificationsAsync(It.IsAny <string>(), It.IsAny <string>()), Times.Once);
        }