Пример #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);
        }
Пример #2
0
        public async Task ShouldGetAllCommentsFromCache()
        {
            Comment[] insertedsComments = { new Comment("text", Guid.NewGuid(), Guid.NewGuid()) };
            _jsonUtilsMock.Deserialize <IEnumerable <Comment> >(Arg.Any <string>()).Returns(insertedsComments);
            _cacheDatabaseMock.Get(Arg.Any <string>()).Returns("comments");
            _reviewRepositoryMock.AlreadyExists(Arg.Any <Guid>()).Returns(true);
            _commentRepositoryMock.CountFromReview(Arg.Any <Guid>()).Returns(1);

            Exception exception = await Record.ExceptionAsync(() => _commentService.GetAllFromReview(Guid.NewGuid().ToString(), new PaginationDTO(1, 10)));

            Assert.Null(exception);
        }
Пример #3
0
        public void ShouldDeserializeObject()
        {
            Guid       guid = Guid.NewGuid();
            BaseEntity obj  = new BaseEntity(guid);

            string     json         = _jsonUtils.Serialize(obj);
            BaseEntity deserialized = _jsonUtils.Deserialize <BaseEntity>(json);

            Assert.Equal(guid, deserialized.Id);
        }
Пример #4
0
        private void SendEmail(string emailMessageJson)
        {
            EmailDTO deserializedObject = _jsonUtils.Deserialize <EmailDTO>(emailMessageJson);

            _mailSendSemaphore.WaitOne();
            try
            {
                _client.Send(_emailConfiguration.From, deserializedObject.To, deserializedObject.Subject, deserializedObject.Body);
            }
            finally
            {
                _mailSendSemaphore.Release();
            }
        }
Пример #5
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));
        }