public void CreateCategories_WithBlogHavingCategories_CreatesCategories()
        {
            // arrange
            var context = new Mock<ISubtextContext>();
            context.Setup(c => c.Blog).Returns(new Blog { Id = 123 });
            bool categoryCreated = false;
            context.Setup(c => c.Repository.CreateLinkCategory(It.IsAny<LinkCategory>())).Callback(() => categoryCreated = true);
            var blog = new BlogMLBlog();
            blog.Categories.Add(new BlogMLCategory { Title = "Category Title", ID = "123" });
            var repository = new BlogImportRepository(context.Object, null, null, new BlogMLImportMapper());

            // act
            repository.CreateCategories(blog);

            // assert
            Assert.IsTrue(categoryCreated);
        }
        public void CreateBlogPost_WithEntryPublisher_PublishesBlogPostAndReturnsId()
        {
            // arrange
            var context = new Mock<ISubtextContext>();
            context.Setup(c => c.Blog).Returns(new Blog());
            var entryPublisher = new Mock<IEntryPublisher>();
            entryPublisher.Setup(p => p.Publish(It.IsAny<Entry>())).Returns(310);
            var blog = new BlogMLBlog();
            var post = new BlogMLPost();
            var repository = new BlogImportRepository(context.Object, null, entryPublisher.Object, new BlogMLImportMapper());

            // act
            var id = repository.CreateBlogPost(blog, post);

            // assert
            Assert.AreEqual("310", id);
        }
        public void CreateBlogPost_WithEntryPublisher_RemovesKeywordExpander()
        {
            // arrange
            var context = new Mock<ISubtextContext>();
            context.Setup(c => c.Blog).Returns(new Blog());
            context.Setup(c => c.Repository.Create(It.IsAny<Entry>(), It.IsAny<IEnumerable<int>>()));
            var transformation = new CompositeTextTransformation();
            var searchengine = new Mock<IIndexingService>();
            var entryPublisher = new EntryPublisher(context.Object, transformation, null, searchengine.Object);
            var keywordExpander = new KeywordExpander((IEnumerable<KeyWord>)null);
            transformation.Add(keywordExpander);
            var blog = new BlogMLBlog() { Title = "MyBlog" };
            var post = new BlogMLPost();
            var repository = new BlogImportRepository(context.Object, null, entryPublisher, new BlogMLImportMapper());

            // act
            repository.CreateBlogPost(blog, post);

            // assert
            Assert.IsFalse(transformation.Contains(keywordExpander));
        }
        public void CreateCategories_WithBlogHavingNoCategories_DoesNotCreateCategories()
        {
            // arrange
            var context = new Mock<ISubtextContext>();
            context.Setup(c => c.Blog).Returns(new Blog { Id = 123 });
            context.Setup(c => c.Repository.CreateLinkCategory(It.IsAny<LinkCategory>())).Throws(new InvalidOperationException());
            var blog = new BlogMLBlog();
            var repository = new BlogImportRepository(context.Object, null, null, new BlogMLImportMapper());

            // act, assert
            repository.CreateCategories(blog);
        }
        public void SetupBlogForImport_ReturnsBlogMLScope()
        {
            // arrange
            var blog = new Blog();
            var repository = new Mock<ObjectRepository>();
            var context = new Mock<ISubtextContext>();
            context.Setup(c => c.Repository).Returns(repository.Object);
            context.Setup(c => c.Blog).Returns(blog);
            var importRepository = new BlogImportRepository(context.Object, null, null, null);

            // act
            var scope = importRepository.SetupBlogForImport() as BlogImportSetup;

            // assert
            Assert.IsNotNull(scope);
            Assert.AreEqual(blog, scope.Blog);
            Assert.AreEqual(repository.Object, scope.Repository);
        }
        public void SetExtendedProperties_WithKeyForTrackbacksEnabled_EnablesTrackbacks()
        {
            // arrange
            var extendedProperties = new BlogMLBlog.ExtendedPropertiesCollection { new Pair<string, string>(BlogMLBlogExtendedProperties.EnableSendingTrackbacks, "true") };
            var context = new Mock<ISubtextContext>();
            var blog = new Blog { TrackbacksEnabled = false };
            context.Setup(c => c.Blog).Returns(blog);
            bool blogUpdated = false;
            context.Setup(c => c.Repository.UpdateBlog(blog)).Callback(() => blogUpdated = true);
            var repository = new BlogImportRepository(context.Object, null, null, null);

            // act
            repository.SetExtendedProperties(extendedProperties);

            // assert
            Assert.IsTrue(blogUpdated);
            Assert.IsTrue(blog.TrackbacksEnabled);
        }
        public void GetAttachmentDirectoryUrl_DelegatesToUrlHelperForUrl()
        {
            // arrange
            var blog = new Blog();
            var context = new Mock<ISubtextContext>();
            context.Setup(c => c.Blog).Returns(blog);
            context.Setup(c => c.UrlHelper.ImageDirectoryUrl(blog)).Returns("/test");
            var repository = new BlogImportRepository(context.Object, null, null, null);

            // act
            var path = repository.GetAttachmentDirectoryUrl();

            // assert
            Assert.AreEqual(@"/test", path);
        }
        public void GetAttachmentDirectoryPath_WithAttachment_CreatesTrackbackUsingTrackbackService()
        {
            // arrange
            var commentService = new Mock<ICommentService>();
            bool trackbackCreated = false;
            commentService.Setup(s => s.Create(It.IsAny<FeedbackItem>(), It.IsAny<bool>())).Callback(() => trackbackCreated = true);

            var repository = new BlogImportRepository(null, commentService.Object, null, new BlogMLImportMapper());

            // act
            repository.CreateTrackback(new BlogMLTrackback(), "123");

            // assert
            Assert.IsTrue(trackbackCreated);
        }
        public void CreateComment_WithComment_CreatesCommentUsingCommentService()
        {
            // arrange
            var commentService = new Mock<ICommentService>();
            bool commentCreated = false;
            commentService.Setup(s => s.Create(It.IsAny<FeedbackItem>(), false/*runFilters*/)).Callback(() => commentCreated = true);

            var repository = new BlogImportRepository(null, commentService.Object, null, new BlogMLImportMapper());

            // act
            repository.CreateComment(new BlogMLComment(), "123");

            // assert
            Assert.IsTrue(commentCreated);
        }