Example #1
0
        public async Task Should_Notify_Using_Custom_Notifiers()
        {
            //Arrange
            var notificationData = new NotificationData();

            //Act
            var before = Clock.Now;
            await _publisher.PublishAsync("TestNotification", notificationData, severity : NotificationSeverity.Success, userIds : new[] { AbpSession.ToUserIdentifier() });

            var after = Clock.Now;

            //Assert
            Predicate <UserNotification[]> predicate = userNotifications =>
            {
                userNotifications.Length.ShouldBe(1);

                var userNotification = userNotifications[0];
                userNotification.State.ShouldBe(UserNotificationState.Unread);
                userNotification.TenantId.ShouldBe(AbpSession.TenantId);
                userNotification.UserId.ShouldBe(AbpSession.UserId.Value);

                var notification = userNotification.Notification;
                notification.CreationTime.ShouldBeInRange(before, after);
                notification.Data.ToString().ShouldBe(notificationData.ToString());
                notification.EntityId.ShouldBe(null);
                notification.EntityType.ShouldBe(null);
                notification.EntityTypeName.ShouldBe(null);
                notification.NotificationName.ShouldBe("TestNotification");
                notification.Severity.ShouldBe(NotificationSeverity.Success);
                notification.TenantId.ShouldBe(AbpSession.TenantId);

                return(true);
            };

            await _realTimeNotifier1.Received().SendNotificationsAsync(Arg.Is <UserNotification[]>(uns => predicate(uns)));

            await _realTimeNotifier2.Received().SendNotificationsAsync(Arg.Is <UserNotification[]>(uns => predicate(uns)));
        }