예제 #1
0
        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));
        }
예제 #2
0
        public static IEntryPublisher CreateEntryPublisher(ISubtextContext subtextContext, IIndexingService searchEngineService)
        {
            var slugGenerator   = new SlugGenerator(FriendlyUrlSettings.Settings, subtextContext.Repository);
            var transformations = new CompositeTextTransformation
            {
                new XhtmlConverter(),
                new EmoticonsTransformation(subtextContext)
            };

            return(new EntryPublisher(subtextContext, transformations, slugGenerator, searchEngineService));
        }
        public void Transform_WithMultipleTransformations_RunsThemAll()
        {
            //arrange
            var transform1 = new Mock<ITextTransformation>();
            transform1.Setup(t => t.Transform(It.IsAny<string>())).Returns<string>(s => s + "t1");
            var transform2 = new Mock<ITextTransformation>();
            transform2.Setup(t => t.Transform(It.IsAny<string>())).Returns<string>(s => s + "t2");
            var composite = new CompositeTextTransformation();
            composite.Add(transform1.Object);
            composite.Add(transform2.Object);

            //act
            string transformed = composite.Transform("This is a test. ");

            //assert
            Assert.AreEqual("This is a test. t1t2", transformed);
        }
예제 #4
0
        /// <summary>
        /// Load your modules or register your services here!
        /// </summary>
        /// <param name="kernel">The kernel.</param>
        public static void RegisterServices(IKernel kernel)
        {
            // Main Services
            kernel.Bind <ITextTransformation>().ToMethod(context =>
            {
                var transform = new CompositeTextTransformation
                {
                    context.Kernel.Get <XhtmlConverter>(),
                    context.Kernel.Get <EmoticonsTransformation>(),
                    context.Kernel.Get <KeywordExpander>()
                };
                return(transform);
            }).InRequestScope();
            kernel.Bind <IBlogLookupService>().To <BlogLookupService>().InSingletonScope();
            kernel.Bind <ICommentService>().To <CommentService>().InRequestScope();
            kernel.Bind <ICommentFilter>().To <CommentFilter>().InRequestScope();
            kernel.Bind <IStatisticsService>().To <StatisticsService>().InRequestScope();
            kernel.Bind <ICommentSpamService>().To <AkismetSpamService>()
            .When(r => !String.IsNullOrEmpty(r.ParentContext.Kernel.Get <Blog>().FeedbackSpamServiceKey))
            .InRequestScope()
            .WithConstructorArgument("apiKey", c => c.Kernel.Get <Blog>().FeedbackSpamServiceKey)
            .WithConstructorArgument("akismetClient", c => null);

            kernel.Bind <ICommentSpamService>().To <NullSpamService>()
            .When(r => String.IsNullOrEmpty(r.ParentContext.Kernel.Get <Blog>().FeedbackSpamServiceKey))
            .InRequestScope();

            var indexingSettings = FullTextSearchEngineSettings.Settings;

            if (indexingSettings.IsEnabled)
            {
                kernel.Bind <Lucene.Net.Store.Directory>()
                .ToMethod(c => FSDirectory.Open(new DirectoryInfo(HostingEnvironment.MapPath(indexingSettings.IndexFolderLocation))))
                .InSingletonScope();
                kernel.Bind <Analyzer>().To <SnowballAnalyzer>().InSingletonScope()
                .WithConstructorArgument("name", indexingSettings.Language)
                .WithConstructorArgument("stopSet", indexingSettings.StopWords);
            }

            BindCoreDependencies(kernel);
            BindGenericDependencies(kernel);
            BindHttpModules(kernel);
        }
예제 #5
0
        public void Transform_WithMultipleTransformations_RunsThemAll()
        {
            //arrange
            var transform1 = new Mock <ITextTransformation>();

            transform1.Setup(t => t.Transform(It.IsAny <string>())).Returns <string>(s => s + "t1");
            var transform2 = new Mock <ITextTransformation>();

            transform2.Setup(t => t.Transform(It.IsAny <string>())).Returns <string>(s => s + "t2");
            var composite = new CompositeTextTransformation();

            composite.Add(transform1.Object);
            composite.Add(transform2.Object);

            //act
            string transformed = composite.Transform("This is a test. ");

            //assert
            Assert.AreEqual("This is a test. t1t2", transformed);
        }
예제 #6
0
        /// <summary>
        /// Updates the specified entry in the data provider.
        /// </summary>
        /// <param name="entry">Entry.</param>
        /// <param name="context"></param>
        /// <returns></returns>
        public static void Update(Entry entry, ISubtextContext context)
        {
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }

            ObjectRepository repository = new DatabaseObjectProvider();
            var transform = new CompositeTextTransformation
            {
                new XhtmlConverter(),
                new EmoticonsTransformation(context),
                new KeywordExpander(repository)
            };

            var searchEngineService = new Mock <IIndexingService>().Object;
            var publisher           = new EntryPublisher(context, transform, new SlugGenerator(FriendlyUrlSettings.Settings), searchEngineService);

            publisher.Publish(entry);
        }
        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));
        }
예제 #8
0
        public override void Load()
        {
            // Main Services
            Bind <ITextTransformation>().ToMethod(context =>
            {
                var transform = new CompositeTextTransformation
                {
                    context.Kernel.Get <XhtmlConverter>(),
                    context.Kernel.Get <EmoticonsTransformation>(),
                    context.Kernel.Get <KeywordExpander>()
                };
                return(transform);
            }).InRequestScope();
            Bind <ICommentService>().To <CommentService>().InRequestScope();
            Bind <ICommentFilter>().To <CommentFilter>().InRequestScope();
            Bind <IStatisticsService>().To <StatisticsService>().InRequestScope();
            Bind <ICommentSpamService>().To <AkismetSpamService>()
            .When(r => !String.IsNullOrEmpty(r.ParentContext.Kernel.Get <Blog>().FeedbackSpamServiceKey))
            .InRequestScope()
            .WithConstructorArgument("apiKey", c => c.Kernel.Get <Blog>().FeedbackSpamServiceKey)
            .WithConstructorArgument("akismetClient", c => null);

            var indexingSettings = FullTextSearchEngineSettings.Settings;

            if (indexingSettings.IsEnabled)
            {
                Bind <Directory>()
                .ToMethod(c => FSDirectory.Open(new DirectoryInfo(c.Kernel.Get <HttpContext>().Server.MapPath(indexingSettings.IndexFolderLocation))))
                .InSingletonScope();
                Bind <Analyzer>().To <SnowballAnalyzer>().InSingletonScope()
                .WithConstructorArgument("name", indexingSettings.Language)
                .WithConstructorArgument("stopSet", indexingSettings.StopWords);
            }

            // Dependencies you're less likely to change.
            LoadCoreDependencies();
            LoadGenericDependencies();
        }
예제 #9
0
        public override void Load()
        {
            // Main Services
            Bind<ITextTransformation>().ToMethod(context =>
                {
                    var transform = new CompositeTextTransformation
                    {
                        context.Kernel.Get<XhtmlConverter>(),
                        context.Kernel.Get<EmoticonsTransformation>(),
                        context.Kernel.Get<KeywordExpander>()
                    };
                    return transform;
                }).InRequestScope();
            Bind<ICommentService>().To<CommentService>().InRequestScope();
            Bind<ICommentFilter>().To<CommentFilter>().InRequestScope();
            Bind<IStatisticsService>().To<StatisticsService>().InRequestScope();
            Bind<ICommentSpamService>().To<AkismetSpamService>()
                .When(r => !String.IsNullOrEmpty(r.ParentContext.Kernel.Get<Blog>().FeedbackSpamServiceKey))
                .InRequestScope()
                .WithConstructorArgument("apiKey", c => c.Kernel.Get<Blog>().FeedbackSpamServiceKey)
                .WithConstructorArgument("akismetClient", c => null);

            var indexingSettings = FullTextSearchEngineSettings.Settings;

            if (indexingSettings.IsEnabled)
            {
                Bind<Directory>()
                    .ToMethod(c => FSDirectory.Open(new DirectoryInfo(c.Kernel.Get<HttpContext>().Server.MapPath(indexingSettings.IndexFolderLocation))))
                    .InSingletonScope();
                Bind<Analyzer>().To<SnowballAnalyzer>().InSingletonScope()
                    .WithConstructorArgument("name", indexingSettings.Language)
                    .WithConstructorArgument("stopSet", indexingSettings.StopWords);
            }

            // Dependencies you're less likely to change.
            LoadCoreDependencies();
            LoadGenericDependencies();
        }
예제 #10
0
        /// <summary>
        /// Load your modules or register your services here!
        /// </summary>
        /// <param name="kernel">The kernel.</param>
        public static void RegisterServices(IKernel kernel)
        {
            // Main Services
            kernel.Bind<ITextTransformation>().ToMethod(context =>
            {
                var transform = new CompositeTextTransformation
                    {
                        context.Kernel.Get<XhtmlConverter>(),
                        context.Kernel.Get<EmoticonsTransformation>(),
                        context.Kernel.Get<KeywordExpander>()
                    };
                return transform;
            }).InRequestScope();
            kernel.Bind<IBlogLookupService>().To<BlogLookupService>().InSingletonScope();
            kernel.Bind<ICommentService>().To<CommentService>().InRequestScope();
            kernel.Bind<ICommentFilter>().To<CommentFilter>().InRequestScope();
            kernel.Bind<IStatisticsService>().To<StatisticsService>().InRequestScope();
            kernel.Bind<ICommentSpamService>().To<AkismetSpamService>()
                .When(r => !String.IsNullOrEmpty(r.ParentContext.Kernel.Get<Blog>().FeedbackSpamServiceKey))
                .InRequestScope()
                .WithConstructorArgument("apiKey", c => c.Kernel.Get<Blog>().FeedbackSpamServiceKey)
                .WithConstructorArgument("akismetClient", c => null);

            kernel.Bind<ICommentSpamService>().To<NullSpamService>()
                .When(r => String.IsNullOrEmpty(r.ParentContext.Kernel.Get<Blog>().FeedbackSpamServiceKey))
                .InRequestScope();

            var indexingSettings = FullTextSearchEngineSettings.Settings;

            if (indexingSettings.IsEnabled)
            {
                kernel.Bind<Lucene.Net.Store.Directory>()
                    .ToMethod(c => FSDirectory.Open(new DirectoryInfo(HostingEnvironment.MapPath(indexingSettings.IndexFolderLocation))))
                    .InSingletonScope();
                kernel.Bind<Analyzer>().To<SnowballAnalyzer>().InSingletonScope()
                    .WithConstructorArgument("name", indexingSettings.Language)
                    .WithConstructorArgument("stopSet", indexingSettings.StopWords);
            }

            BindCoreDependencies(kernel);
            BindGenericDependencies(kernel);
            BindHttpModules(kernel);
        }