예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }