Encapsulates settings for friendly URL generation.
コード例 #1
0
        public void ConvertTitleToSlug_WithDotSeparator_UsesDot()
        {
            //arrange
            var config = new NameValueCollection();
            config.Add("limitWordCount", "10");
            config.Add("separatingCharacter", ".");
            var settings = new FriendlyUrlSettings(config);
            var generator = new SlugGenerator(settings);
            var entry = new Entry(PostType.BlogPost) {Title = "this is a test"};

            //act
            string slug = generator.GetSlugFromTitle(entry);

            //act
            Assert.AreEqual("this.is.a.test", slug);
        }
コード例 #2
0
        public void ConvertTitleToSlug_UsingDash_NormalizesDashes()
        {
            //arrange
            var config = new NameValueCollection();
            config.Add("limitWordCount", "10");
            config.Add("separatingCharacter", "-");
            var settings = new FriendlyUrlSettings(config);
            var generator = new SlugGenerator(settings);
            var entry = new Entry(PostType.BlogPost) {Title = "-this - is - a - test-"};

            //act
            string slug = generator.GetSlugFromTitle(entry);

            //act
            Assert.AreEqual("this-is-a-test", slug);
        }
コード例 #3
0
        public void ConvertTitleToSlug_WithTitleEndingInPeriod_RemovesTrailingPeriod()
        {
            //arrange
            var config = new NameValueCollection();
            config.Add("limitWordCount", "10");
            config.Add("separatingCharacter", "-");
            var settings = new FriendlyUrlSettings(config);
            var generator = new SlugGenerator(settings);
            var entry = new Entry(PostType.BlogPost) {Title = "a test."};

            //act
            string slug = generator.GetSlugFromTitle(entry);

            //act
            Assert.AreEqual("a-test", slug);
        }
コード例 #4
0
        public void ConvertTitleToSlug_WithTextTransformToUpperCase_TransformsUrlToUpperCase()
        {
            //arrange
            var config = new NameValueCollection();
            config.Add("limitWordCount", "10");
            config.Add("separatingCharacter", ".");
            config.Add("TextTransform", "UpperCase");
            var settings = new FriendlyUrlSettings(config);
            var generator = new SlugGenerator(settings);
            var entry = new Entry(PostType.BlogPost) {Title = "this is a test"};

            //act
            string slug = generator.GetSlugFromTitle(entry);

            //act
            Assert.AreEqual("THIS.IS.A.TEST", slug);
        }
コード例 #5
0
        public void ConvertTitleToSlug_WithNullCharacterDelimiterAndSpacesInTitle_RemovesSpacesAndPascalCasesTitle()
        {
            //arrange
            var config = new NameValueCollection();
            config.Add("limitWordCount", "10");
            config.Add("separatingCharacter", "");
            var settings = new FriendlyUrlSettings(config);
            var generator = new SlugGenerator(settings);
            var entry = new Entry(PostType.BlogPost) {Title = " this is a test "};

            //act
            string slug = generator.GetSlugFromTitle(entry);

            //act
            Assert.AreEqual("ThisIsATest", slug);
        }
コード例 #6
0
        public void ConvertTitleToSlug_WithMoreWordsThanAllowed_TruncatesRemainingWords()
        {
            //arrange
            var config = new NameValueCollection();
            config.Add("limitWordCount", "2");
            config.Add("separatingCharacter", "_");
            var settings = new FriendlyUrlSettings(config);
            var generator = new SlugGenerator(settings);
            var entry = new Entry(PostType.BlogPost) {Title = "this is a test"};

            //act
            string slug = generator.GetSlugFromTitle(entry);

            //act
            Assert.AreEqual("this_is", slug);
        }
コード例 #7
0
 public SlugGenerator(FriendlyUrlSettings slugSettings, ObjectProvider repository)
 {
     SlugSettings = slugSettings ?? DefaultSettings;
     Repository = repository;
 }
コード例 #8
0
 public SlugGenerator(FriendlyUrlSettings slugSettings)
     : this(slugSettings, null)
 {
 }