Пример #1
0
        public void ReturnAllCommentsForArticle_WhenParameterIsCorrect()
        {
            // Arrange
            var dbContextMock = new Mock <ApplicationDbContext>();

            var articleId = 1;
            var comment   = new Comment();
            var comments  = new List <Comment>()
            {
                comment
            };
            var article = new Article()
            {
                Id       = articleId,
                Comments = comments
            };
            var articles = new List <Article>()
            {
                article
            };

            var articlesSetMock = new Mock <DbSet <Article> >();

            articlesSetMock.SetupData(articles);

            dbContextMock.Setup(m => m.Articles).Returns(articlesSetMock.Object);

            var service = new ArticleServices(dbContextMock.Object);

            // Act
            var result = service.AllComments(articleId).ToList();

            // Assert
            CollectionAssert.AreEqual(comments, result);
        }