Ejemplo n.º 1
0
        public async Task Delete(string commentId, string userId)
        {
            Comment registeredComment;

            string commentRegisteredOnCacheJson = await _cacheDatabase.Get(commentId);

            if (commentRegisteredOnCacheJson != null)
            {
                registeredComment = _jsonUtils.Deserialize <Comment>(commentRegisteredOnCacheJson);
            }
            else
            {
                registeredComment = await _commentRepository.GetById(Guid.Parse(commentId));

                if (registeredComment == null)
                {
                    throw new ResourceNotFoundException("comment not found.");
                }
            }

            ThrowIfAuthenticatedUserNotIsCommentCreator(registeredComment, Guid.Parse(userId));

            _commentRepository.Delete(registeredComment);
            await _commentRepository.Save();

            await _cacheDatabase.Remove(commentId);
        }
Ejemplo n.º 2
0
        public async Task <PaginationResponseModel <ReviewResponseModel> > GetAll(PaginationDTO pagination)
        {
            IEnumerable <Review> reviews;
            int count = await _reviewRepository.Count();

            string reviewsInsertedOnCacheJson = await _cacheDatabase.Get($"reviews?page={pagination.Page}&quantityPerPage={pagination.QuantityPerPage}");

            if (reviewsInsertedOnCacheJson != null)
            {
                reviews = _jsonUtils.Deserialize <IEnumerable <Review> >(reviewsInsertedOnCacheJson);
            }
            else
            {
                reviews = await _reviewRepository.GetAll(pagination);

                if (reviews.Count() > 0)
                {
                    await _cacheDatabase.Set($"reviews?page={pagination.Page}&quantityPerPage={pagination.QuantityPerPage}", _jsonUtils.Serialize(reviews));
                }
            }

            return(CreatePaginationResult(reviews, count, pagination));
        }
Ejemplo n.º 3
0
 public CacheUser GetUser(string connectionId)
 {
     return(_cacheDatabase.Get <CacheUser>(USER_KEY + connectionId));
 }
Ejemplo n.º 4
0
        public async Task ShouldThrowResourceNotFoundExceptionOnCreateCommentWithNotExistsReview()
        {
            _cacheDatabaseMock.Get(Arg.Any <string>()).Returns(null as string);
            _reviewRepositoryMock.AlreadyExists(Arg.Any <Guid>()).Returns(false);
            CreateCommentRequestModel requestModel = new CreateCommentRequestModel()
            {
                Text = "TEXT"
            };

            Exception exception = await Record.ExceptionAsync(() => _commentService.Create(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), requestModel));

            Assert.IsType <ResourceNotFoundException>(exception);
        }