Esempio n. 1
0
        public void NotificationService_MarkNotificationAsRead_NotificationNotAssignedToCurrentUser_ShouldThrowUnauthorizedException()
        {
            // Arrange
            const string userId         = "TestUser";
            const int    notificationId = 1;
            var          notification   = new Models.Entities.Notification
            {
                Id = notificationId,
                AssignedToUserId = "OtherUser",
                IsRead           = false
            };

            _mockNotificationRepository.Setup(_ => _.GetAsync(It.IsAny <int>())).ReturnsAsync(notification);

            // Act
            Func <Task> throwAction = async() => await _notificationService.MarkNotificationAsRead(userId, notificationId);

            // Assert
            throwAction.ShouldThrow <UnauthorizedException>();
        }
Esempio n. 2
0
        public async void NotificationService_MarkNotificationAsRead_ShouldMarkNotificationAsRead()
        {
            // Arrange
            const string userId         = "TestUser";
            const int    notificationId = 1;
            var          notification   = new Models.Entities.Notification
            {
                Id = notificationId,
                AssignedToUserId = userId,
                IsRead           = false
            };

            _mockNotificationRepository.Setup(_ => _.GetAsync(It.IsAny <int>())).ReturnsAsync(notification);
            _mockNotificationRepository.Setup(_ => _.SaveChangesAsync()).ReturnsAsync(1);

            // Act
            await _notificationService.MarkNotificationAsRead(userId, notificationId);

            // Assert
            notification.IsRead.Should().BeTrue();
        }