Exemplo n.º 1
0
        public void GetLikeByArticleIdFound()
        {
            int articleId = 5;
            int count     = 2;

            // Mock
            this._likeRespository
            .Setup(b => b.FindByArticleId(articleId))
            .ReturnsAsync(Like.Create(articleId, count));

            // Act
            var result = _getLikeByArticleIdUseCase.Execute(articleId).Result;

            // Assert
            Assert.Equal(articleId, result.ArticleId);
            Assert.Equal(count, result.Count);
        }
Exemplo n.º 2
0
        public async Task <Like> Execute(int articleId)
        {
            try
            {
                var like = await _getLikeByArticleIdUseCase.Execute(articleId);

                if (like == null)
                {
                    like = Like.Create(articleId, 0);
                }

                return(like);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public void InsertLikeSuccess()
        {
            Like like = Like.Create(5, 10);

            // Mock
            this._likeRespository
            .Setup(b => b.Save(like))
            .Returns(like);

            this._unitOfWork
            .Setup(b => b.SaveChangesAsync());

            // Act
            var result = _insertLikeUseCase.Execute(like).Result;

            // Assert
            Assert.Equal(like.ArticleId, result.ArticleId);
            Assert.Equal(like.Count, result.Count);
        }
        public async Task <Like> Execute(int articleId)
        {
            try
            {
                var like = await _getLikeByArticleIdUseCase.Execute(articleId);

                if (like == null)
                {
                    like = Like.Create(articleId, 1);
                }
                else
                {
                    like.SetCount(like.Count + 1);
                }

                return(await _insertLikeUseCase.Execute(like));
            }
            catch (Exception)
            {
                throw;
            }
        }
        public async Task <Dictionary <string, object> > Handle(CreateLike request, CancellationToken cancellationToken)
        {
            string requestAddress         = "https://localhost:5001/api/users/username/" + request.Username;
            string likeUserRequestAddress = "https://localhost:5001/api/users/" + request.PersonId;
            string userResponseString     = await client.GetStringAsync(requestAddress);

            string likeUSerResponseString = await client.GetStringAsync(likeUserRequestAddress);

            UserResponse userResponse     = JsonConvert.DeserializeObject <UserResponse>(userResponseString);
            UserResponse likeUSerResponse = JsonConvert.DeserializeObject <UserResponse>(likeUSerResponseString);
            var          response         = new Dictionary <string, object>();
            var          succes           = true;
            var          emailSent        = false;

            if (request.PersonLike == 1)
            {
                emailSent = SendEmail(userResponse.user.Email, likeUSerResponse.user.UserName);
            }

            try
            {
                var like = Like.Create(request.PersonId, request.PetId, userResponse.user.Id, request.PersonLike, request.PetLike);
                LikeContext.Likes.Add(like);
                await LikeContext.SaveChangesAsync(cancellationToken);

                response.Add("like", like);
            }
            catch (InvalidOperationException)
            {
                succes = false;
            }

            response.Add("succes", succes);
            response.Add("emailSent", emailSent);
            return(response);
        }