BlogImportRepositoryTests.cs :  » Bloggers » SubText » UnitTests » Subtext » BlogMl » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Bloggers » SubText 
SubText » UnitTests » Subtext » BlogMl » BlogImportRepositoryTests.cs
using System;
using System.Collections.Generic;
using BlogML;
using BlogML.Xml;
using MbUnit.Framework;
using Moq;
using Subtext.Framework;
using Subtext.Framework.Components;
using Subtext.Framework.Providers;
using Subtext.Framework.Services;
using Subtext.Framework.Services.SearchEngine;
using Subtext.ImportExport;

namespace UnitTests.Subtext.BlogMl{
    [TestFixture]
    public class BlogImportRepositoryTests
    {
        [Test]
        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);
        }

        [Test]
        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);
        }

        [Test]
        public void CreateBlogPost_WithEntryPublisher_PublishesBlogPostAndReturnsId()
        {
            // arrange
            var context = new Mock<ISubtextContext>();
            context.Setup(c => c.Blog.TimeZone.FromUtc(It.IsAny<DateTime>())).Returns(DateTime.Now);
            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);
        }

        [Test]
        public void CreateBlogPost_WithEntryPublisher_RemovesKeywordExpander()
        {
            // arrange
            var context = new Mock<ISubtextContext>();
            context.Setup(c => c.Blog.TimeZone.FromUtc(It.IsAny<DateTime>())).Returns(DateTime.Now);
            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));
        }

        [Test]
        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);
        }

        [Test]
        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);
        }

        [Test]
        public void CreateTrackback_WithTrackback_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);
        }

        [Test]
        public void GetAttachmentDirectoryPath_DelegatesToUrlHelperForPath()
        {
            // arrange
            var blog = new Blog();
            var context = new Mock<ISubtextContext>();
            context.Setup(c => c.Blog).Returns(blog);
            context.Setup(c => c.UrlHelper.ImageDirectoryPath(blog)).Returns(@"c:\web\images");
            var repository = new BlogImportRepository(context.Object, null, null, null);

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

            // assert
            Assert.AreEqual(@"c:\web\images", path);
        }

        [Test]
        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);
        }

        [Test]
        public void SetupBlogForImport_ReturnsBlogMLScope()
        {
            // arrange
            var blog = new Blog();
            var repository = new Mock<ObjectProvider>();
            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);
        }

        [Test]
        public void SetExtendedProperties_WithKeyForCommentModeration_EnablesModeration()
        {
            // arrange
            var extendedProperties = new BlogMLBlog.ExtendedPropertiesCollection
            {new Pair<string, string>(BlogMLBlogExtendedProperties.CommentModeration, "true")};
            var context = new Mock<ISubtextContext>();
            var blog = new Blog {ModerationEnabled = 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.ModerationEnabled);
        }

        [Test]
        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);
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.