public void GetAll_When16ArticlesInDb_ShouldReturn10Articles()
        {
            Article[] articles = this.GenerateValidTestArticles(16);

            var repo = Mock.Create<IRepository<Article>>();
            Mock.Arrange(() => repo.All())
                .Returns(() => articles.AsQueryable());

            var data = Mock.Create<IArticlesData>();

            Mock.Arrange(() => data.Articles)
                .Returns(() => repo);

            var controller = new ArticlesController(data);
            this.SetupController(controller);

            var actionResult = controller.Get();

            var response = actionResult.ExecuteAsync(CancellationToken.None).Result;

            var actual = response.Content.ReadAsAsync<IEnumerable<ArticleDataModel>>().Result.Select(a => a.ID).ToList();

            var expected = articles.AsQueryable()
                .OrderByDescending(a => a.DateCreated)
                .Take(10)
                .Select(a => a.ID).ToList();

            CollectionAssert.AreEquivalent(expected, actual);
        }
        public void GetById_ReturnsArticleWithCorrectId()
        {
            // Arrange
            int testId = 5;
            var data = Mock.Create<IArticlesData>();
            Mock.Arrange(() => data.Articles.Find(testId)).Returns(new Article() { Id = testId });
            var controller = new ArticlesController(data);

            // Act
            IHttpActionResult actionResult = controller.GetById(testId);
            var contentResult = actionResult as OkNegotiatedContentResult<ArticleDetailsViewModel>;

            // Assert
            Assert.IsNotNull(contentResult);
            Assert.IsNotNull(contentResult.Content);
            Assert.AreEqual(testId, contentResult.Content.Id);
        }
        public void GetAll_WhenArticlesInDb_ShouldReturnArticles()
        {
            Article[] articles = this.GenerateValidTestArticles(1);

            var data = Mock.Create<IArticlesData>();
            Mock.Arrange(() => data.Articles.All()).Returns(() => articles.AsQueryable());

            var controller = new ArticlesController(data);
            this.SetupController(controller);

            IHttpActionResult actionResult = controller.Get();
            var response = actionResult.ExecuteAsync(CancellationToken.None).Result;
            var actual = response.Content.ReadAsAsync<IEnumerable<ArticleViewModel>>().Result.Select(a => a.Id).ToList();

            var expected = articles.AsQueryable().Select(a => a.Id).ToList();

            CollectionAssert.AreEquivalent(expected, actual);
        }