private FakeDataSource CreateFakeDataSource()
        {
            FakeDataSource fakeDataSource = new FakeDataSource();

            sitemapIndexConfiguration.Setup(configuration => configuration.DataSource).Returns(fakeDataSource);
            return(fakeDataSource);
        }
        public void Take_TakesItemCountToTake()
        {
            FakeDataSource fakeDataSource = new FakeDataSource();

            fakeDataSource.Take(12);

            fakeDataSource.TakenItemCount.Should().Be(12);
        }
        public void Count_WhenCountIsNotSet_ThrowsException()
        {
            FakeDataSource fakeDataSource = new FakeDataSource();

            Action act = () => { fakeDataSource.Count(); };

            act.Should().Throw <NotImplementedException>();
        }
        public void Skip_SetsItemCountToSkip()
        {
            FakeDataSource fakeDataSource = new FakeDataSource();

            fakeDataSource.Skip(10);

            fakeDataSource.SkippedItemCount.Should().Be(10);
        }
        public void CreateSitemapWithConfiguration_HttpContextIsNull_ThrowsException()
        {
            FakeDataSource dataSource = new FakeDataSource();

            Action act = () => _sitemapProvider.CreateSitemap(null, dataSource, _config.Object);

            act.ShouldThrow <ArgumentNullException>();
        }
        public void CreateSitemapWithConfiguration_PageSizeIsBiggerThanNodeCount_CreatesSitemap()
        {
            var sitemapNodes = new FakeDataSource(CreateMany <SampleData>()).WithCount(1);

            _config.Setup(item => item.Size).Returns(5);

            _config.Setup(item => item.CreateNode(It.IsAny <SampleData>())).Returns(new SitemapNode());
            _actionResultFactory.Setup(item => item.CreateSitemapResult(_httpContext.Object, It.IsAny <SitemapModel>())).Returns(_expectedResult);

            ActionResult result = _sitemapProvider.CreateSitemap(_httpContext.Object, sitemapNodes, _config.Object);

            result.Should().Be(_expectedResult);
            sitemapNodes.TakenItemCount.Should().NotHaveValue();
            sitemapNodes.SkippedItemCount.Should().NotHaveValue();
        }
        public void CreateSitemapWithConfiguration_AsksForSpecificPage_CreatesSitemap()
        {
            FakeDataSource datas = new FakeDataSource(CreateMany <SampleData>()).WithCount(5);

            _config.Setup(item => item.Size).Returns(2);
            _config.Setup(item => item.CurrentPage).Returns(2);
            _config.Setup(item => item.CreateNode(It.IsAny <SampleData>())).Returns(new SitemapNode());
            _actionResultFactory.Setup(item => item.CreateSitemapResult(_httpContext.Object, It.IsAny <SitemapModel>())).Returns(_expectedResult);

            ActionResult result = _sitemapProvider.CreateSitemap(_httpContext.Object, datas, _config.Object);

            result.Should().Be(_expectedResult);
            datas.TakenItemCount.Should().Be(2);
            datas.SkippedItemCount.Should().Be(2);
        }
        public void CreateSitemapWithConfiguration_NodeCountIsGreaterThanPageSize_CreatesIndex(int?currentPage)
        {
            FakeDataSource datas = new FakeDataSource().WithCount(5).WithEnumerationDisabled();

            _config.Setup(item => item.Size).Returns(2);
            _config.Setup(item => item.CurrentPage).Returns(currentPage);
            _config.Setup(item => item.CreateSitemapUrl(It.Is <int>(i => i <= 3))).Returns(string.Empty);

            Expression <Func <SitemapIndexModel, bool> > validateIndex = index => index.Nodes.Count == 3;

            _actionResultFactory.Setup(item => item.CreateSitemapResult(_httpContext.Object, It.Is(validateIndex))).Returns(_expectedResult);


            ActionResult result = _sitemapProvider.CreateSitemap(_httpContext.Object, datas, _config.Object);

            result.Should().Be(_expectedResult);
            datas.SkippedItemCount.Should().NotHaveValue();
            datas.TakenItemCount.Should().NotHaveValue();
        }
        public void Count_WhenCountIsSet_ReturnsCount()
        {
            FakeDataSource fakeDataSource = new FakeDataSource().WithCount(7);

            fakeDataSource.Count().Should().Be(7);
        }