Example #1
0
        public async Task ExistAsync_10_ReturnsValidIsExist()
        {
            // Arrange
            const int  expectedId        = TorrentsCount;
            const bool expectedCondition = true;

            // Act
            var isExist = await _torrentRepository.ExistAsync(expectedId);

            // Assert
            Assert.Equal(expectedCondition, isExist);
        }
Example #2
0
        public async Task <Comment> AddAsync(Comment comment)
        {
            Guard.Against.NullInvalid(comment, Resources.Comment_Invalid_ErrorMessage);
            Guard.Against.NullString(comment.Text, Resources.Comment_InvalidText_ErrorMessage);
            Guard.Against.NullString(comment.UserId, Resources.User_InvalidId_ErrorMessage);
            Guard.Against.LessOne(comment.TorrentId, Resources.Torrent_InvalidId_ErrorMessage);

            if (!await _torrentRepository.ExistAsync(comment.TorrentId))
            {
                throw new RutrackerException(
                          string.Format(Resources.Torrent_NotFoundById_ErrorMessage, comment.TorrentId),
                          ExceptionEventTypes.InvalidParameters);
            }

            comment.AddedDate = _dateService.Now();

            var result = await _commentRepository.AddAsync(comment);

            await _unitOfWork.SaveChangesAsync();

            return(result);
        }