Beispiel #1
0
        public Comment AddComment(int articleId, string text, string email)
        {
            var userId = _db.Users.Single(x => x.Email == email).Id;

            var comment = new Comment
            {
                UserId = userId,
                DateCreated = DateTime.Now,
                ArticleId = articleId,
                Text = text
            };

            _db.Comments.Add(comment);
            _db.SaveChanges();

            return comment;
        }
        public void AddComment_ValidModel_ReturnCommentViewModel()
        {
            var comment = new Comment
            {
                ArticleId = 1,
                Text = "Good article",
                DateCreated = DateTime.Now,
                User = new User
                {
                    Forename = "Test",
                    Surname = "User"
                }
            };

            _fakeArticleService.Setup(x => x.AddComment(It.IsAny<int>(), It.IsAny<string>(), It.IsAny<string>())).Returns(comment);

            var result = _articleController.AddComment(comment.ArticleId, comment.Text);

            Assert.IsInstanceOf<CommentViewModel>(result.Data);
        }