Exemplo n.º 1
0
        public void ConvertTitleToSlug_WithAllNumericTitle_PrependsLetterNToAvoidConflicts()
        {
            //arrange
            var generator = new SlugGenerator(null);
            var entry = new Entry(PostType.BlogPost) {Title = @"1234"};

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

            //act
            Assert.AreEqual("n_1234", slug);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        public void ConvertTitleToSlug_WithSpacesInTitle_ReplacesSpacesInTitle()
        {
            //arrange
            var generator = new SlugGenerator(null);
            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);
        }
Exemplo n.º 7
0
        public void ConvertTitleToSlug_WithSlugMatchingTwoExistingEntries_AppendsAgainToSlug()
        {
            //arrange
            var repository = new Mock<ObjectRepository>();
            repository.Setup(r => r.GetEntry("foo-bar", false, false)).Returns(new Entry(PostType.BlogPost));
            repository.Setup(r => r.GetEntry("foo-bar-Again", false, false)).Returns(new Entry(PostType.BlogPost));
            repository.Setup(r => r.GetEntry("foo-bar-Yet-Again", false, false)).Returns((Entry)null);
            var generator = new SlugGenerator(null, repository.Object);
            var entry = new Entry(PostType.BlogPost) {Title = @"foo bar"};

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

            //act
            Assert.AreEqual("foo-bar-yet-again", slug);
        }
Exemplo n.º 8
0
        public void ConvertTitleToSlug_WithNonEuropeanInternationalizedTitles_ConvertsToUrlEncodedTitle()
        {
            //arrange
            var generator = new SlugGenerator(null);
            var entry = new Entry(PostType.BlogPost) {Title = "안-녕하십니까"};

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

            //act
            Assert.AreEqual("%ec%95%88-%eb%85%95%ed%95%98%ec%8b%ad%eb%8b%88%ea%b9%8c", slug);
        }
Exemplo n.º 9
0
        public void ConvertTitleToSlug_WithNullOrEmptyTitle_ThrowsArgumentException()
        {
            //arrange
            var generator = new SlugGenerator(null);
            var entry = new Entry(PostType.BlogPost) {Title = string.Empty};

            //act, assert
            UnitTestHelper.AssertThrows<ArgumentException>(() => generator.GetSlugFromTitle(entry));
        }
Exemplo n.º 10
0
        public void ConvertTitleToSlug_WithSlugAndAllPrefixesMatchingExistingEntries_ThrowsException()
        {
            //arrange
            var repository = new Mock<ObjectRepository>();
            repository.Setup(r => r.GetEntry(It.IsAny<string>(), false, false)).Returns(new Entry(PostType.BlogPost));
            repository.Setup(r => r.GetEntry("foo-bar-again", false, false)).Returns((Entry)null);
            var generator = new SlugGenerator(null, repository.Object);
            var entry = new Entry(PostType.BlogPost) {Title = @"foo bar"};

            //act, assert
            UnitTestHelper.AssertThrows<InvalidOperationException>(() => generator.GetSlugFromTitle(entry));
        }
Exemplo n.º 11
0
        public void ConvertTitleToSlug_WithNullEntry_ThrowsArgumentNullException()
        {
            //arrange
            var generator = new SlugGenerator(null);

            //act, assert
            UnitTestHelper.AssertThrowsArgumentNullException(() => generator.GetSlugFromTitle(null));
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
0
        public void ConvertTitleToSlug_WithNonWordCharacters_RemoveNonWordCharacters()
        {
            //arrange
            var generator = new SlugGenerator(null);
            var entry = new Entry(PostType.BlogPost) {Title = @"[!""'`;:~@#foo$%^&-bar*(){\[}\]?+/=\\|<>_baz"};

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

            //act
            Assert.AreEqual("foo-bar_baz", slug);
        }
Exemplo n.º 14
0
        public void ConvertTitleToSlug_WithInternationalizedTitles_ConvertsToAnsiUrlSlug()
        {
            //arrange
            var generator = new SlugGenerator(null);
            var entry = new Entry(PostType.BlogPost) {Title = "Åñçhòr çùè Héllò wörld"};

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

            //act
            Assert.AreEqual("anchor-cue-hello-world", slug);
        }
Exemplo n.º 15
0
        public void ConvertTitleToSlug_WithSlugMatchingSixExistingEntries_AppendsUniqueSuffixToSlug()
        {
            //arrange
            var repository = new Mock<ObjectRepository>();
            repository.Setup(r => r.GetEntry("foo-bar", false, false)).Returns(new Entry(PostType.BlogPost));
            repository.Setup(r => r.GetEntry("foo-bar-Again", false, false)).Returns(new Entry(PostType.BlogPost));
            repository.Setup(r => r.GetEntry("foo-bar-Yet-Again", false, false)).Returns(new Entry(PostType.BlogPost));
            repository.Setup(r => r.GetEntry("foo-bar-And-Again", false, false)).Returns(new Entry(PostType.BlogPost));
            repository.Setup(r => r.GetEntry("foo-bar-Once-Again", false, false)).Returns(new Entry(PostType.BlogPost));
            repository.Setup(r => r.GetEntry("foo-bar-Once-More", false, false)).Returns(new Entry(PostType.BlogPost));
            repository.Setup(r => r.GetEntry("foo-bar-To-Beat-A-Dead-Horse", false, false)).Returns((Entry)null);
            var generator = new SlugGenerator(null, repository.Object);
            var entry = new Entry(PostType.BlogPost) {Title = @"foo bar"};

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

            //act
            Assert.AreEqual("foo-bar-to-beat-a-dead-horse", slug);
        }
Exemplo n.º 16
0
        public int Publish(Entry entry)
        {
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }

            if (entry.PostType == PostType.None)
            {
                throw new ArgumentException(Resources.InvalidOperation_PostTypeIsNone, "entry");
            }

            entry.Body = Transformation.Transform(entry.Body);

            if (String.IsNullOrEmpty(entry.EntryName))
            {
                entry.EntryName = SlugGenerator.GetSlugFromTitle(entry);
            }
            if (entry.EntryName.IsNumeric())
            {
                entry.EntryName = "n_" + entry.EntryName;
            }
            if (NullValue.IsNull(entry.DateCreated))
            {
                entry.DateCreated = SubtextContext.Blog.TimeZone.Now;
            }
            if (NullValue.IsNull(entry.DateModified))
            {
                entry.DateModified = SubtextContext.Blog.TimeZone.Now;
            }
            if (entry.IsActive)
            {
                if (NullValue.IsNull(entry.DateSyndicated) && entry.IncludeInMainSyndication)
                {
                    entry.DateSyndicated = SubtextContext.Blog.TimeZone.Now;
                }
            }
            else
            {
                entry.DateSyndicated = NullValue.NullDateTime;
            }

            IEnumerable <int> categoryIds = null;

            if (entry.Categories.Count > 0)
            {
                categoryIds = GetCategoryIdsFromCategoryTitles(entry);
            }

            try
            {
                if (NullValue.IsNull(entry.Id))
                {
                    SubtextContext.Repository.Create(entry, categoryIds);
                }
                else
                {
                    SubtextContext.Repository.Update(entry, categoryIds);
                }
            }
            catch (DbException e)
            {
                if (e.Message.Contains("pick a unique EntryName"))
                {
                    throw new DuplicateEntryException(Resources.DuplicateEntryException_EntryNameAlreadyExists, e);
                }
                throw;
            }

            ValidateEntry(entry);
            IList <string> tags = entry.Body.ParseTags();

            SubtextContext.Repository.SetEntryTagList(entry.Id, tags);
            IndexingService.AddPost(entry, tags);
            return(entry.Id);
        }
Exemplo n.º 17
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);
        }