Пример #1
0
 public IActionResult GetCommentsOfTeamsUserFollows(int userId)
 {
     try
     {
         IEnumerable <Comment> comments = commentService.GetCommentsOfTeamsUserFollows(userId);
         if (comments.Count() > 0)
         {
             List <CommentModelOut> commentsOut = new List <CommentModelOut>();
             foreach (Comment comment in comments)
             {
                 CommentModelOut modelOut = new CommentModelOut(comment);
                 commentsOut.Add(modelOut);
             }
             return(Ok(commentsOut));
         }
         else
         {
             return(Ok("No existen comentarios para los equipos que el usuario sigue"));
         }
     }
     catch (NotExistsException ex)
     {
         return(BadRequest(ex.Message));
     }
 }
        public void CommentOnMatchTest()
        {
            //Arrange.
            User          commentarist = GetFakeUser();
            CommentaryDto made         = new CommentaryDto()
            {
                makerUsername = commentarist.UserName, text = "this is a comment"
            };

            CommentModelIn input = new CommentModelIn()
            {
                Text = "this is a comment"
            };

            matchService.Setup(ms => ms.CommentOnEncounter(3, "username", input.Text)).Returns(made);


            //Act.
            IActionResult        result        = controller.CommentOnMatch(3, input);
            CreatedAtRouteResult createdResult = result as CreatedAtRouteResult;
            CommentModelOut      comment       = createdResult.Value as CommentModelOut;

            //Assert.
            matchService.Verify(ms => ms.CommentOnEncounter(3, "username", input.Text), Times.Once);
            Assert.IsNotNull(result);
            Assert.IsNotNull(createdResult);
            Assert.AreEqual(201, createdResult.StatusCode);
            Assert.AreEqual("GetCommentById", createdResult.RouteName);
            Assert.IsNotNull(comment);
            Assert.AreEqual(comment.Text, input.Text);
            Assert.AreEqual("username", comment.MakerUsername);
        }
Пример #3
0
 public IActionResult GetUserCommentsForGame(int userId, int gameId)
 {
     try
     {
         IEnumerable <Comment>  comments    = commentService.GetUserCommentsForAGame(userId, gameId);
         List <CommentModelOut> commentsOut = new List <CommentModelOut>();
         if (comments.Count() > 0)
         {
             foreach (Comment comment in comments)
             {
                 CommentModelOut model = new CommentModelOut(comment);
                 commentsOut.Add(model);
             }
             return(Ok(commentsOut));
         }
         else
         {
             return(Ok("No existen comentarios para el equipo"));
         }
     }
     catch (NotExistsException ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Пример #4
0
        private CommentModelOut BuildCommentModelOut(CommentaryDto aComment)
        {
            CommentModelOut comment = new CommentModelOut()
            {
                Id            = aComment.commentId,
                MakerUsername = aComment.makerUsername,
                Text          = aComment.text
            };

            return(comment);
        }
Пример #5
0
        private IActionResult TryGetComment(int id)
        {
            CommentaryDto   comment = encounterService.GetComment(id);
            CommentModelOut output  = new CommentModelOut
            {
                Id            = comment.commentId,
                MakerUsername = comment.makerUsername,
                Text          = comment.text
            };

            return(Ok(output));
        }
Пример #6
0
        private IActionResult TryAddComment(int matchId, CommentModelIn input)
        {
            string          username = HttpContext.User.Claims.First(c => c.Type.Equals(AuthenticationConstants.USERNAME_CLAIM)).Value;
            CommentaryDto   created  = encounterService.CommentOnEncounter(matchId, username, input.Text);
            CommentModelOut output   = new CommentModelOut
            {
                Id            = created.commentId,
                MakerUsername = username,
                Text          = input.Text
            };

            return(CreatedAtRoute("GetCommentById", new { id = output.Id }, output));
        }
Пример #7
0
        public IActionResult Get(int id)
        {
            Comment comment = commentService.GetCommentById(id);

            if (comment != null)
            {
                CommentModelOut modelOut = new CommentModelOut(comment);
                return(Ok(modelOut));
            }
            else
            {
                return(BadRequest("No existe el comentario buscado"));
            }
        }
Пример #8
0
        public IActionResult Get()
        {
            IEnumerable <Comment> comments = commentService.GetAllComments();

            if (comments.Count() > 0)
            {
                List <CommentModelOut> commentsOut = new List <CommentModelOut>();
                foreach (Comment comment in comments)
                {
                    CommentModelOut modelOut = new CommentModelOut(comment);
                    commentsOut.Add(modelOut);
                }
                return(Ok(commentsOut));
            }
            else
            {
                return(Ok("No existen comentarios en el sistema"));
            }
        }
Пример #9
0
 public IActionResult Post([FromBody] CommentModelIn commentModel)
 {
     try
     {
         if (ModelState.IsValid)
         {
             Comment comment = commentModel.TransformToEntity();
             comment = commentService.CreateComment(comment);
             CommentModelOut modelOut = new CommentModelOut(comment);
             return(CreatedAtRoute("GetComment", new { id = comment.Id }, modelOut));
         }
         else
         {
             return(BadRequest(ModelState));
         }
     } catch (NotExistsException ex)
     {
         return(BadRequest(ex.Message));
     }
 }
        public void ViewCommentTest()
        {
            //Arrange.
            User          dummyUser    = GetFakeUser();
            CommentaryDto dummyComment = new CommentaryDto()
            {
                text = "Comment", makerUsername = dummyUser.UserName
            };

            matchService.Setup(ms => ms.GetComment(3)).Returns(dummyComment);

            //Act.
            IActionResult   result   = controller.GetComment(3);
            OkObjectResult  okResult = result as OkObjectResult;
            CommentModelOut comment  = okResult.Value as CommentModelOut;

            //Assert.
            Assert.IsNotNull(result);
            Assert.IsNotNull(okResult);
            Assert.AreEqual(200, okResult.StatusCode);
            Assert.IsNotNull(comment);
            Assert.AreEqual(dummyComment.text, comment.Text);
        }