public void ReturnCorrectResultWhenThereAreComments()
        {
            var firstCommentContent  = "test";
            var secondCommentContent = "test2";

            var mockedUnitOfWork = new Mock <IUnitOfWork>();
            var mockedRepository = new Mock <IRepository <Comment> >();
            var commentsService  = new CommentsService(mockedRepository.Object, mockedUnitOfWork.Object);

            var mockedFirstComment = new Mock <Comment>().Object;

            mockedFirstComment.Content = firstCommentContent;

            var mockedSecondComment = new Mock <Comment>().Object;

            mockedSecondComment.Content = secondCommentContent;

            var comments = new List <Comment>();

            comments.Add(mockedFirstComment);
            comments.Add(mockedSecondComment);

            mockedRepository.Setup(x => x.GetAll).Returns(comments.AsQueryable <Comment>);

            var result = commentsService.GetAllComments();

            Assert.AreEqual(comments, result);
        }
        public void CallCommentsRepositoryGetAllMethod()
        {
            var mockedUnitOfWork = new Mock <IUnitOfWork>();
            var mockedRepository = new Mock <IRepository <Comment> >();
            var commentsService  = new CommentsService(mockedRepository.Object, mockedUnitOfWork.Object);

            var result = commentsService.GetAllComments();

            mockedRepository.Verify(x => x.GetAll, Times.Once());
        }
        public void ReturnEmptyCollectionWhenThereAreNoComments()
        {
            var mockedUnitOfWork = new Mock <IUnitOfWork>();
            var mockedRepository = new Mock <IRepository <Comment> >();
            var commentsService  = new CommentsService(mockedRepository.Object, mockedUnitOfWork.Object);

            var comments = new List <Comment>();

            mockedRepository.Setup(x => x.GetAllWithDeleted).Returns(comments.AsQueryable <Comment>);

            var result = commentsService.GetAllComments();

            Assert.IsEmpty(result);
        }
Exemplo n.º 4
0
 public IEnumerable <CommentsModel> Get()
 {
     return(_commentsService.GetAllComments());
 }
Exemplo n.º 5
0
 // GET: Admin/Comments
 public ActionResult Index()
 {
     return(View(_commentsService.GetAllComments().ToList()));
 }