예제 #1
0
        public async Task RetrieveNotifications_ShouldThrowAnInvalidUserIdExceptionWhenUserIdIsNegativeAsync()
        {
            // Arrange
            var requestDto = new RetrieveNotificationRequest(
                -1
                );

            // Act
            var exception = await Assert.ThrowsAsync <InvalidUserIdException>(() => _sut.RetrieveNotifications(requestDto));

            // Assert
            Assert.Equal("UserID is invalid", exception.Message);
        }
예제 #2
0
        public async Task RetrieveNotifications_ShouldReturnAListOfNotificationsAsync()
        {
            // Arrange
            var requestDto = new RetrieveNotificationRequest(
                1
                );
            var responseDto = new RetrieveNotificationsResponse(_mockedListDto);

            _notificationRepoMock.Setup(n =>
                                        n.RetrieveNotifications(requestDto)).ReturnsAsync(_mockedListDto);

            // Act
            var notificationList = await _sut.RetrieveNotifications(requestDto);

            // Assert
            Assert.Equal(responseDto.Notifications, notificationList.Notifications);
        }
        public async Task <RetrieveNotificationsResponse> RetrieveNotifications(RetrieveNotificationRequest request)
        {
            if (request == null)
            {
                throw new InvalidNotificationRequestException("Invalid RetrieveNotificationRequest object");
            }
            if (request.UserId is 0 or < 0)
            {
                throw new InvalidUserIdException("UserID is invalid");
            }

            var response = new RetrieveNotificationsResponse(
                await _repository.RetrieveNotifications(request)
                );


            return(response);
        }
예제 #4
0
 public async Task <RetrieveNotificationsResponse> RetrieveNotifications([FromQuery] RetrieveNotificationRequest request)
 {
     return(await _service.RetrieveNotifications(request));
 }
        /// <inheritdoc />
        public async Task <List <Models.Notification.Notification> > RetrieveNotifications(RetrieveNotificationRequest request)
        {
            IQueryable <Models.Notification.Notification> retrieveUserNotifications = _context.Notifications.Where(notification => notification.UserID == request.UserId);

            if (retrieveUserNotifications.ToList().IsNullOrEmpty())
            {
                return(null);
            }

            return(await retrieveUserNotifications.ToListAsync());
        }