public void FetchForPage_GIVEN_BlogPostRepository_Has_2_Posts_And_PostsPerPage_Is_1_WHEN_pageNumber_Is_1_THEN_Returns_1_BlogPost()
        {
            const int PostsPerPage = 1;
            const int NumberOfPosts = 2;
            const int PageNumber = 1;

            var mockedBlogPostRepository = CreateMockedBlogPostRepository(NumberOfPosts);

            var pager = new BlogPostPager(PostsPerPage, mockedBlogPostRepository.Object);
            IEnumerable<BlogPost> posts = pager.FetchForPage(PageNumber);

            posts.Count().ShouldEqual(PostsPerPage);
        }
        public void FetchForPage_GIVEN_BlogPostRepository_Has_2_Posts_And_PostsPerPage_Is_1_WHEN_pageNumber_Is_1_THEN_Calls_BlogPostRepository_GetPosts_With_numberToSkip_As_0_numberToTake_As_1()
        {
            const int PostsPerPage = 1;
            const int NumberOfPosts = 2;
            const int PageNumber = 1;

            const int ExpectedNumSkip = 0;
            const int ExpectedNumTake = 1;

            Expression<Action<IBlogPostRepository>> verifiableAction = r => r.GetPosts(ExpectedNumSkip, ExpectedNumTake, It.IsAny<IEnumerable<string>>());

            var mockedBlogPostRepository = CreateMockedBlogPostRepository(NumberOfPosts);
            mockedBlogPostRepository.Setup(verifiableAction).Verifiable();

            var pager = new BlogPostPager(PostsPerPage, mockedBlogPostRepository.Object);
            pager.FetchForPage(PageNumber);

            mockedBlogPostRepository.Verify(verifiableAction, Times.Once());
        }
        public void FetchForPage_WHEN_No_Tags_THEN_Calls_BlogPostRepository_GetPosts_With_EmptyList_Of_Tags()
        {
            IEnumerable<string> tagsPassedToPosts = new string[0];

            var mockedBlogPostRepository = CreateMockedBlogPostRepository(1);
            mockedBlogPostRepository.Setup(r => r.GetPosts(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<IEnumerable<string>>()))
                                    .Callback<int, int, IEnumerable<string>>((skip, take, tags) => tagsPassedToPosts = tags);

            var pager = new BlogPostPager(1, mockedBlogPostRepository.Object);
            IEnumerable<BlogPost> posts = pager.FetchForPage(1, null);

            tagsPassedToPosts.Count().ShouldEqual(0);
        }
        public void FetchForPage_GIVEN_BlogPostRepository_Has_2_Posts_And_PostsPerPage_Is_1_WHEN_pageNumber_Is_3_THEN_Does_Not_Call_BlogPostRepository_GetPosts()
        {
            const int PostsPerPage = 1;
            const int NumberOfPosts = 2;
            const int PageNumber = 3;

            Expression<Action<IBlogPostRepository>> verifiableAction = r => r.GetPosts(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<IEnumerable<string>>());

            var mockedBlogPostRepository = CreateMockedBlogPostRepository(NumberOfPosts);
            mockedBlogPostRepository.Setup(verifiableAction).Verifiable();

            var pager = new BlogPostPager(PostsPerPage, mockedBlogPostRepository.Object);
            pager.FetchForPage(PageNumber);

            mockedBlogPostRepository.Verify(verifiableAction, Times.Never());
        }