public void IndexService_WithNotPublishedPost_DoesntAddsPostToIndex()
        {
            var context = new Mock<ISubtextContext>();
            var searchEngine = new Mock<ISearchEngineService>();
            searchEngine.Setup(s => s.AddPost(It.IsAny<SearchEngineEntry>())).Never();

            var indexService = new IndexingService(context.Object, searchEngine.Object);

            var entry = new Entry(PostType.BlogPost)
            {
                Title = "Sample Post",
                Blog = new Blog() { Title = "My Blog" },
                IsActive = false,
            };

            indexService.AddPost(entry);
        }
        public void IndexService_WithNotPublishedPost_RemovesPostFromIndex()
        {
            var context = new Mock<ISubtextContext>();
            var searchEngine = new Mock<ISearchEngineService>();
            bool deleted = false;
            searchEngine.Setup(s => s.RemovePost(It.IsAny<int>())).Callback(() => deleted = true);

            var indexService = new IndexingService(context.Object, searchEngine.Object);

            var entry = new Entry(PostType.BlogPost)
            {
                Title = "Sample Post",
                Blog = new Blog() { Title = "My Blog" },
                IsActive = false,
            };

            indexService.AddPost(entry);
            Assert.IsTrue(deleted);
        }
        public void IndexService_WithPublishedPost_AddsPostToIndex()
        {
            var context = new Mock<ISubtextContext>();
            var searchEngine = new Mock<ISearchEngineService>();
            SearchEngineEntry entry = null;
            searchEngine.Setup(s => s.AddPost(It.IsAny<SearchEngineEntry>())).Callback<SearchEngineEntry>(e => entry = e);

            var indexService = new IndexingService(context.Object, searchEngine.Object);

            var blogEntry = new Entry(PostType.BlogPost)
                            {
                                Title ="Sample Post",
                                Blog = new Blog() { Title = "My Blog" },
                                IsActive=true,
                            };

            indexService.AddPost(blogEntry);
            Assert.IsNotNull(entry);
        }
        public void RebuildIndex_WithEntryNotPublished_DoesntAddsDataToIndex()
        {
            var context = new Mock<ISubtextContext>();
            var repository = new Mock<ObjectProvider>();
            repository.Setup(r => r.GetEntries(PostType.BlogPost, null, It.IsAny<int>(), It.IsAny<int>())).Returns(
                BuildFakeCollectionNotPublished());
            context.Setup(c => c.Repository).Returns(repository.Object);

            var indexService = new IndexingService(context.Object, _service);

            indexService.RebuildIndex();

            Assert.AreEqual(0, _service.GetTotalIndexedEntryCount());
        }
        public void RebuildIndex_LoadEntriesFromRepository()
        {
            var context = new Mock<ISubtextContext>();
            var repository = new Mock<ObjectProvider>();
            repository.Setup(r => r.GetEntries(PostType.BlogPost, null, It.IsAny<int>(), It.IsAny<int>())).Returns(
                new PagedCollection<EntryStatsView>());
            context.Setup(c => c.Repository).Returns(repository.Object);

            var indexService = new IndexingService(context.Object, _service);

            indexService.RebuildIndex();

            repository.Verify(rep => rep.GetEntries(PostType.BlogPost, null, It.IsAny<int>(), It.IsAny<int>()));
        }