Inheritance: IIdentifiable
Example #1
0
        /// <summary>
        /// Creates the specified entry in the back end data store attaching 
        /// the specified category ids.
        /// </summary>
        /// <param name="entry">Entry.</param>
        /// <param name="categoryIds">Category I ds.</param>
        /// <returns></returns>
        public override int Create(Entry entry, IEnumerable<int> categoryIds)
        {
            ValidateEntry(entry);

            entry.DateCreatedUtc = entry.DateCreatedUtc.IsNull() ? CurrentDateTimeUtc : entry.DateCreatedUtc;

            entry.Id = _procedures.InsertEntry(entry.Title
                , entry.Body.NullIfEmpty()
                , (int)entry.PostType
                , entry.Author.NullIfEmpty()
                , entry.Email.NullIfEmpty()
                , entry.Description.NullIfEmpty()
                , BlogId
                , entry.DateCreatedUtc
                , (int)entry.PostConfig
                , entry.EntryName.NullIfEmpty()
                , entry.DatePublishedUtc.NullIfEmpty());

            if (categoryIds != null)
            {
                SetEntryCategoryList(entry.Id, categoryIds);
            }

            if (entry.Id > -1)
            {
                Config.CurrentBlog.DateModifiedUtc = entry.DateCreatedUtc;
            }

            return entry.Id;
        }
Example #2
0
        /// <summary>
        /// Posts trackbacks and pingbacks for the specified entry.
        /// </summary>
        public static void Run(Entry entry, Blog blog, BlogUrlHelper urlHelper)
        {
            if (!blog.TrackbacksEnabled)
            {
                return;
            }

            if (!Config.Settings.Tracking.EnablePingBacks && !Config.Settings.Tracking.EnableTrackBacks)
            {
                return;
            }

            if (entry != null)
            {
                VirtualPath blogUrl = urlHelper.BlogUrl();
                Uri fullyQualifiedUrl = blogUrl.ToFullyQualifiedUrl(blog);

                var notify = new Notifier
                {
                    FullyQualifiedUrl = fullyQualifiedUrl.AbsoluteUri,
                    BlogName = blog.Title,
                    Title = entry.Title,
                    PostUrl = urlHelper.EntryUrl(entry).ToFullyQualifiedUrl(blog),
                    Description = entry.HasDescription ? entry.Description : entry.Title,
                    Text = entry.Body
                };

                //This could take a while, do it on another thread
                ThreadHelper.FireAndForget(notify.Notify, "Exception occured while attempting trackback notification");
            }
        }
        public Entry ConvertBlogPost(BlogMLPost post, BlogMLBlog blogMLBlog, Blog blog)
        {
            DateTime dateModified = blog != null ? blog.TimeZone.FromUtc(post.DateModified) : post.DateModified;
            DateTime dateCreated = blog != null ? blog.TimeZone.FromUtc(post.DateCreated) : post.DateCreated;

            var newEntry = new Entry((post.PostType == BlogPostTypes.Article) ? PostType.Story : PostType.BlogPost)
            {
                Title = GetTitleFromPost(post).Left(BlogPostTitleMaxLength),
                DateCreated = dateCreated,
                DateModified = dateModified,
                DateSyndicated = post.Approved ? dateModified : DateTime.MaxValue,
                Body = post.Content.UncodedText,
                IsActive = post.Approved,
                DisplayOnHomePage = post.Approved,
                IncludeInMainSyndication = post.Approved,
                IsAggregated = post.Approved,
                AllowComments = true,
                Description = post.HasExcerpt ? post.Excerpt.UncodedText: null
            };

            if(!string.IsNullOrEmpty(post.PostName))
            {
                newEntry.EntryName = post.PostName;
            }
            else
            {
                SetEntryNameForBlogspotImport(post, newEntry);
            }

            SetEntryAuthor(post, newEntry, blogMLBlog);

            SetEntryCategories(post, newEntry, blogMLBlog);
            return newEntry;
        }
Example #4
0
        public void editPost_WithEntryHavingEnclosure_UpdatesEntryEnclosureWithNewEnclosure()
        {
            //arrange
            var entry = new Entry(PostType.BlogPost) { Title = "Title 1", Body = "Blah", IsActive = true };
            entry.DateCreatedUtc = entry.DatePublishedUtc = entry.DateModifiedUtc = DateTime.ParseExact("1975/01/23", "yyyy/MM/dd", CultureInfo.InvariantCulture);
            entry.Categories.Add("TestCategory");
            var blog = new Blog { Id = 123, Host = "localhost", AllowServiceAccess = true, UserName = "******", Password = "******" };
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.Setup(c => c.Blog).Returns(blog);
            subtextContext.Setup(c => c.Repository.GetEntry(It.IsAny<Int32>(), false, true)).Returns(entry);
            var entryPublisher = new Mock<IEntryPublisher>();
            Entry publishedEntry = null;
            entryPublisher.Setup(p => p.Publish(It.IsAny<Entry>())).Callback<Entry>(e => publishedEntry = e);
            FrameworkEnclosure enclosure = UnitTestHelper.BuildEnclosure("<Digital Photography Explained (for Geeks) with Aaron Hockley/>",
                                              "http://perseus.franklins.net/hanselminutes_0107.mp3", "audio/mp3", 123, 26707573, true, true);
            entry.Enclosure = enclosure;
            var post = new Post { title = "Title 2", description = "Blah", dateCreated = DateTime.UtcNow };

            var postEnclosure = new Enclosure
            {
                url = "http://codeclimber.net.nz/podcast/mypodcastUpdated.mp3",
                type = "audio/mp3",
                length = 123456789
            };
            post.enclosure = postEnclosure;
            var metaWeblog = new MetaWeblog(subtextContext.Object, entryPublisher.Object);

            // act
            bool result = metaWeblog.editPost("123", "username", "password", post, true);

            // assert
            Assert.IsTrue(result);
            Assert.IsNotNull(publishedEntry.Enclosure);
            Assert.AreEqual("http://codeclimber.net.nz/podcast/mypodcastUpdated.mp3", entry.Enclosure.Url);
        }
Example #5
0
        /// <summary>
        /// Creates the specified entry in the back end data store attaching 
        /// the specified category ids.
        /// </summary>
        /// <param name="entry">Entry.</param>
        /// <param name="categoryIds">Category I ds.</param>
        /// <returns></returns>
        public override int Create(Entry entry, IEnumerable<int> categoryIds)
        {
            ValidateEntry(entry);

            entry.Id = _procedures.InsertEntry(entry.Title
                , entry.Body.NullIfEmpty()
                , (int)entry.PostType
                , entry.Author.NullIfEmpty()
                , entry.Email.NullIfEmpty()
                , entry.Description.NullIfEmpty()
                , BlogId
                , entry.DateCreated
                , (int)entry.PostConfig
                , entry.EntryName.NullIfEmpty()
                , entry.DateSyndicated.NullIfEmpty()
                , CurrentDateTime);

            if(categoryIds != null)
            {
                SetEntryCategoryList(entry.Id, categoryIds);
            }

            if(entry.Id > -1)
            {
                Config.CurrentBlog.LastUpdated = entry.DateCreated;
            }

            return entry.Id;
        }
        public void CreateSetsDateCreated()
        {
            //arrange
            var blog = new Mock<Blog>();
            DateTime dateCreatedUtc = DateTime.UtcNow;
            blog.Object.Id = 1;
            var entry = new Entry(PostType.BlogPost, blog.Object) { Id = 123, BlogId = 1, CommentingClosed = false };
            var repository = new Mock<ObjectRepository>();
            repository.Setup(r => r.GetEntry(It.IsAny<int>(), true, true)).Returns(entry);
            var context = new Mock<ISubtextContext>();
            context.SetupGet(c => c.Repository).Returns(repository.Object);
            context.SetupGet(c => c.Blog).Returns(blog.Object);
            context.SetupGet(c => c.HttpContext.Items).Returns(new Hashtable());
            context.SetupGet(c => c.Cache).Returns(new TestCache());

            var service = new CommentService(context.Object, null);
            var comment = new FeedbackItem(FeedbackType.Comment) { EntryId = 123, BlogId = 1, Body = "test", Title = "title" };

            //act
            service.Create(comment, true/*runFilters*/);

            //assert
            Assert.GreaterEqualThan(comment.DateCreatedUtc, dateCreatedUtc);
            Assert.GreaterEqualThan(DateTime.UtcNow, comment.DateCreatedUtc);
        }
Example #7
0
        public void CanUpdatePostWithCategories()
        {
            string hostname = UnitTestHelper.GenerateRandomString();
            Assert.IsTrue(Config.CreateBlog("", "username", "password", hostname, ""));
            UnitTestHelper.SetHttpContextWithBlogRequest(hostname, "");
            Config.CurrentBlog.AllowServiceAccess = true;

            string category1Name = UnitTestHelper.GenerateRandomString();
            string category2Name = UnitTestHelper.GenerateRandomString();
            UnitTestHelper.CreateCategory(Config.CurrentBlog.Id, category1Name);
            UnitTestHelper.CreateCategory(Config.CurrentBlog.Id, category2Name);

            Entry entry = new Entry(PostType.BlogPost);
            entry.Title = "Title 1";
            entry.Body = "Blah";
            entry.IsActive = true;
            entry.DateCreated = entry.DateSyndicated = entry.DateModified = DateTime.ParseExact("1975/01/23", "yyyy/MM/dd", CultureInfo.InvariantCulture);
            entry.Categories.Add(category1Name);
            int entryId = Entries.Create(entry);

            MetaWeblog api = new MetaWeblog();
            Post post = new Post();
            post.title = "Title 2";
            post.description = "Blah";
            post.categories = new string[] { category2Name };
            post.dateCreated = DateTime.Now;

            bool result = api.editPost(entryId.ToString(CultureInfo.InvariantCulture), "username", "password", post, true);

            entry = Entries.GetEntry(entryId, PostConfig.None, true);
            Assert.AreEqual(1, entry.Categories.Count, "We expected one category. We didn't get what we expected.");
            Assert.AreEqual(category2Name, entry.Categories[0], "Category has not been updated correctly.");
        }
Example #8
0
        /// <summary>
        /// Creates the specified entry in the back end data store attaching 
        /// the specified category ids.
        /// </summary>
        /// <param name="entry">Entry.</param>
        /// <param name="categoryIds">Category I ds.</param>
        /// <returns></returns>
        public override int Create(Entry entry, int[] categoryIds)
        {
            if(!FormatEntry(entry,true))
            {
                throw new BlogFailedPostException("Failed post exception");
            }

            entry.Id = DbProvider.Instance().InsertEntry(entry);

            if(categoryIds != null)
            {
                DbProvider.Instance().SetEntryCategoryList(entry.Id, categoryIds);
            }

            if(entry.Id > -1 && Config.Settings.Tracking.UseTrackingServices)
            {
                entry.Url = Config.CurrentBlog.UrlFormats.EntryUrl(entry);
            }

            if(entry.Id > -1)
            {
                Config.CurrentBlog.LastUpdated = entry.DateCreated;
            }

            return entry.Id;
        }
        public void CreateDoesNotChangeDateCreatedAndDateModifiedIfAlreadySpecified()
        {
            //arrange
            var blog = new Mock<Blog>();
            DateTime dateCreated = DateTime.Now;
            blog.Object.Id = 1;
            blog.Setup(b => b.TimeZone.Now).Returns(dateCreated);
            var entry = new Entry(PostType.BlogPost, blog.Object) {Id = 123, BlogId = 1, CommentingClosed = false};
            var repository = new Mock<ObjectProvider>();
            repository.Setup(r => r.GetEntry(It.IsAny<int>(), true, true)).Returns(entry);
            var context = new Mock<ISubtextContext>();
            context.SetupGet(c => c.Repository).Returns(repository.Object);
            context.SetupGet(c => c.Blog).Returns(blog.Object);
            context.SetupGet(c => c.HttpContext.Items).Returns(new Hashtable());
            context.SetupGet(c => c.Cache).Returns(new TestCache());

            var service = new CommentService(context.Object, null);
            var comment = new FeedbackItem(FeedbackType.Comment)
            {
                EntryId = 123,
                BlogId = 1,
                Body = "test",
                Title = "title",
                DateCreated = dateCreated.AddDays(-2),
                DateModified = dateCreated.AddDays(-1)
            };

            //act
            service.Create(comment, true/*runFilters*/);

            //assert
            Assert.AreEqual(dateCreated.AddDays(-2), comment.DateCreated);
            Assert.AreEqual(dateCreated.AddDays(-1), comment.DateModified);
        }
Example #10
0
        /// <summary>
        /// Posts trackbacks and pingbacks for the specified entry.
        /// </summary>
        /// <param name="entry">The entry.</param>
        public static void Run(Entry entry)
        {
            if(entry != null)
            {
                Notifier notify = new Notifier();

                notify.FullyQualifiedUrl = Config.CurrentBlog.RootUrl.ToString();
                notify.BlogName = Config.CurrentBlog.Title;

                notify.Title = entry.Title;

                notify.PostUrl = entry.FullyQualifiedUrl;

                if(entry.HasDescription)
                {
                    notify.Description = entry.Description;
                }
                else
                {
                    notify.Description = entry.Title;
                }

                notify.Text = entry.Body;

                //This could take a while, do it on another thread
                ManagedThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(notify.Notify));
            }
        }
Example #11
0
        //Body of text to insert into a post with Trackback
        public static string TrackBackTag(Entry entry)
        {
            if (entry == null)
            {
                throw new ArgumentNullException("entry", Resources.ArgumentNull_Generic);
            }

            return String.Format(CultureInfo.InvariantCulture, Resources.TrackbackTag, entry.FullyQualifiedUrl, entry.FullyQualifiedUrl, entry.Title, Config.CurrentBlog.RootUrl, entry.Id.ToString(CultureInfo.InvariantCulture));
        }
Example #12
0
 public EntryViewModel(Entry entry, ISubtextContext context)
 {
     if (entry == null)
     {
         throw new ArgumentNullException("entry");
     }
     Entry = entry;
     SubtextContext = context;
 }
Example #13
0
        //Text to insert into a file with pingback service location
        public static string GetPingbackTag(BlogUrlHelper urlHelper, Entry entry)
        {
            VirtualPath blogUrl = urlHelper.BlogUrl();
            Uri absoluteUrl = blogUrl.ToFullyQualifiedUrl(entry.Blog);

            return string.Format(CultureInfo.InvariantCulture,
                "<link rel=\"pingback\" href=\"{0}Services/Pingback/{1}.aspx\"></link>",
                absoluteUrl.AbsoluteUri,
                entry.Id);
        }
        public void EntryExtensionMethodsTest_ConvertToSearchEngineEntry_WithTags_ConvertsTagsToString()
        {
            Entry post = new Entry(PostType.BlogPost)
                             {
                                 Blog = new  Blog(){ Title="MyTitle", BlogGroupId=1},
                             };
            IList<String> tags = new List<string>() {"tag1","tag2"};
            SearchEngineEntry searchEntry = post.ConvertToSearchEngineEntry(tags);

            Assert.AreEqual("tag1,tag2", searchEntry.Tags);
        }
        public void EntryExtensionMethodsTest_ConvertToSearchEngineEntry_WithOutTags_ConvertsTagsToString()
        {
            Entry post = new Entry(PostType.BlogPost)
            {
                Blog = new Blog() { Title = "MyTitle", BlogGroupId = 1 },
                Body = "<a href=\"http://blah.com/subdir/tag1/\" rel=\"tag\">tag1</a><a href=\"http://blah.com/another-dir/tag2/\" rel=\"tag\">tag2</a>"
            };
            SearchEngineEntry searchEntry = post.ConvertToSearchEngineEntry();

            Assert.AreEqual("tag1,tag2", searchEntry.Tags);
        }
        public void EntryExtensionMethodsTest_ConvertToSearchEngineEntry_StripsHtmlTags()
        {
            Entry post = new Entry(PostType.BlogPost)
            {
                Blog = new Blog() { Title = "MyTitle", BlogGroupId = 1 },
                Body = "this is <b>bold</b> text"
            };
            SearchEngineEntry searchEntry = post.ConvertToSearchEngineEntry();

            Assert.AreEqual("this is bold text", searchEntry.Body);
        }
Example #17
0
        //Body of text to insert into a post with Trackback
        public static string TrackBackTag(Entry entry, Blog blog, BlogUrlHelper urlHelper)
        {
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }

            Uri entryUrl = urlHelper.EntryUrl(entry).ToFullyQualifiedUrl(blog);
            return String.Format(CultureInfo.InvariantCulture, Resources.TrackbackTag, entryUrl, entryUrl, entry.Title,
                                 urlHelper.BlogUrl(), entry.Id.ToString(CultureInfo.InvariantCulture));
        }
Example #18
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);
        }
Example #19
0
 protected static void BindCurrentEntryControls(Entry entry, Control root)
 {
     foreach(Control control in root.Controls)
     {
         CurrentEntryControl currentEntryControl = control as CurrentEntryControl;
         if(currentEntryControl != null)
         {
             currentEntryControl.Entry = entry;
             currentEntryControl.DataBind();
         }
     }
 }
        public void CommentRssWriterProducesValidEmptyFeed()
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", "blog");

            BlogInfo blogInfo = new BlogInfo();
            blogInfo.Host = "localhost";
            blogInfo.Subfolder = "blog";
            blogInfo.Email = "*****@*****.**";
            blogInfo.RFC3229DeltaEncodingEnabled = true;
            blogInfo.Title = "My Blog Rulz";
            blogInfo.TimeZoneId = PacificTimeZoneId;

            HttpContext.Current.Items.Add("BlogInfo-", blogInfo);

            Entry entry = new Entry(PostType.None);
            entry.AllowComments = true;
            entry.Title = "Comments requiring your approval.";
            entry.Url = "/Admin/Feedback.aspx?status=2";
            entry.Body = "The following items are waiting approval.";
            entry.PostType = PostType.None;
            ModeratedCommentRssWriter writer = new ModeratedCommentRssWriter(new List<FeedbackItem>(), entry);

            string expected = @"<rss version=""2.0"" "
                                    + @"xmlns:dc=""http://purl.org/dc/elements/1.1/"" "
                                    + @"xmlns:trackback=""http://madskills.com/public/xml/rss/module/trackback/"" "
                                    + @"xmlns:wfw=""http://wellformedweb.org/CommentAPI/"" "
                                    + @"xmlns:slash=""http://purl.org/rss/1.0/modules/slash/"" "
                                    + @"xmlns:copyright=""http://blogs.law.harvard.edu/tech/rss"" "
                                    + @"xmlns:image=""http://purl.org/rss/1.0/modules/image/"">" + Environment.NewLine
                                + indent() + @"<channel>" + Environment.NewLine
                                        + indent(2) + @"<title>Comments requiring your approval.</title>" + Environment.NewLine
                                        + indent(2) + @"<link>http://localhost/blog/Admin/Feedback.aspx?status=2</link>" + Environment.NewLine
                                        + indent(2) + @"<description>The following items are waiting approval.</description>" + Environment.NewLine
                                        + indent(2) + @"<language>en-US</language>" + Environment.NewLine
                                        + indent(2) + @"<copyright>Subtext Weblog</copyright>" + Environment.NewLine
                                        + indent(2) + @"<generator>{0}</generator>" + Environment.NewLine
                                        + indent(2) + @"<image>" + Environment.NewLine
                                            + indent(3) + @"<title>Comments requiring your approval.</title>" + Environment.NewLine
                                            + indent(3) + @"<url>http://localhost/images/RSS2Image.gif</url>" + Environment.NewLine
                                            + indent(3) + @"<link>http://localhost/blog/Admin/Feedback.aspx?status=2</link>" + Environment.NewLine
                                            + indent(3) + @"<width>77</width>" + Environment.NewLine
                                            + indent(3) + @"<height>60</height>" + Environment.NewLine
                                        + indent(2) + @"</image>" + Environment.NewLine
                                + indent(1) + @"</channel>" + Environment.NewLine
                              + @"</rss>";

            expected = string.Format(expected, VersionInfo.VersionDisplayText);

            Console.WriteLine("EXPECTED: " + expected);
            Console.WriteLine("ACTUAL  : " + writer.Xml);
            Assert.AreEqual(expected, writer.Xml);
        }
        protected override IList<Subtext.Framework.Components.FeedbackItem> GetFeedEntries()
        {
            BlogInfo blogInfo = Config.CurrentBlog;
            ParentEntry = new Entry(PostType.None);
            ParentEntry.AllowComments = true;
            ParentEntry.Title = "Comments requiring your approval.";
            ParentEntry.Url = "/Admin/Feedback.aspx?status=2";

            ParentEntry.Body = "The following items are waiting approval.";// = new Uri(blogInfo.RootUrl + "Admin/Feedback.aspx");
            //ParentEntry.FullyQualifiedUrl
            FeedbackCounts counts = FeedbackItem.GetFeedbackCounts();
            IList<FeedbackItem> moderatedFeedback = FeedbackItem.GetPagedFeedback(0, counts.NeedsModerationCount, FeedbackStatusFlag.NeedsModeration, FeedbackType.None);

            return moderatedFeedback;
        }
Example #22
0
        public void GetEntriesByCategory_WithEntriesInCache_RetrievesFromCache()
        {
            // arrange
            var entry = new Entry(PostType.BlogPost) { Title = "Testing Cacher" };
            var context = new Mock<ISubtextContext>();
            context.Setup(c => c.Blog).Returns(new Blog { Id = 1001 });
            context.Setup(c => c.Cache["EC:Count10Category1BlogId1001"]).Returns(new List<Entry> { entry });
            context.Setup(c => c.Repository.GetEntriesByCategory(10, 1, true /*activeOnly*/)).Throws(new Exception("Repository should not have been accessed"));

            // act
            var cachedEntries = Cacher.GetEntriesByCategory(10 /*count*/, 1 /*categoryId*/, context.Object);

            // assert
            Assert.AreEqual(entry, cachedEntries.First());
        }
Example #23
0
        public void AutoGeneratedUrlSetInEntryInstance()
        {
            string hostname = UnitTestHelper.GenerateRandomString();
            Assert.IsTrue(Config.CreateBlog("", "username", "password", hostname, ""));
            UnitTestHelper.SetHttpContextWithBlogRequest(hostname, "", "");

            Entry entry = new Entry(PostType.BlogPost);
            entry.DateCreated = DateTime.ParseExact("2005/01/23", "yyyy/MM/dd", CultureInfo.InvariantCulture);
            entry.Title = "Some Really Random Title";
            entry.Body = "Some Body";
            entry.DateSyndicated = entry.DateCreated.AddMonths(1);
            entry.IsActive = true;
            Entries.Create(entry);

            Assert.AreEqual("http://" + hostname + "/archive/2005/02/23/Some_Really_Random_Title.aspx", entry.FullyQualifiedUrl.ToString());
        }
Example #24
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);
        }
Example #25
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);
        }
        public void Ctor_CopiesAllPropertiesOfEntry()
        {
            // arrange
            var entry = new Entry(PostType.BlogPost);
            entry.Id = 123;
            entry.FeedBackCount = 99;
            entry.Title = "The title";

            // act
            var model = new EntryViewModel(entry, null);

            // assert
            Assert.AreEqual(PostType.BlogPost, model.PostType);
            Assert.AreEqual(123, model.Id);
            Assert.AreEqual(99, model.FeedBackCount);
            Assert.AreEqual("The title", model.Title);
        }
        public void IndexService_WithNotPublishedPost_DoesntAddsPostToIndex()
        {
            var context = new Mock<ISubtextContext>();
            var searchEngine = new Mock<ISearchEngineService>();
            searchEngine.Setup(s => s.AddPost(It.IsAny<SearchEngineEntry>())).Never();

            var indexService = new IndexingService(context.Object, searchEngine.Object);

            var entry = new Entry(PostType.BlogPost)
            {
                Title = "Sample Post",
                Blog = new Blog() { Title = "My Blog" },
                IsActive = false,
            };

            indexService.AddPost(entry);
        }
        public static void AddCommunityCredits(Entry entry, BlogUrlHelper urlHelper, Blog blog)
        {
            string result;

            bool commCreditsEnabled;

            if (!bool.TryParse(ConfigurationManager.AppSettings["CommCreditEnabled"], out commCreditsEnabled))
            {
                return;
            }

            if (commCreditsEnabled && entry.IsActive)
            {
                var wsCommunityCredit = new AffiliateServices();

                string url = urlHelper.EntryUrl(entry).ToFullyQualifiedUrl(blog).ToString();
                string category = String.Empty;
                if (entry.PostType == PostType.BlogPost)
                {
                    category = "Blog";
                }
                else if (entry.PostType == PostType.Story)
                {
                    category = "Article";
                }
                string description = "Blogged about: " + entry.Title;

                string firstName = string.Empty;
                string lastName = blog.Author;
                string email = blog.Email;
                string affiliateCode = ConfigurationManager.AppSettings["CommCreditAffiliateCode"];
                string affiliateKey = ConfigurationManager.AppSettings["CommCreditAffiliateKey"];

                Log.InfoFormat("Sending notification to community credit for url {0} in category {1} for user {2}", url,
                               category, email);

                result = wsCommunityCredit.AddCommunityCredit(email, firstName, lastName, description, url, category,
                                                              affiliateCode, affiliateKey);

                Log.InfoFormat("Response Received was: {0}", result);
                if (!result.Equals("Success"))
                {
                    throw new CommunityCreditNotificationException(result);
                }
            }
        }
Example #29
0
        public string GetSlugFromTitle(Entry entry)
        {
            if(entry == null)
            {
                throw new ArgumentNullException("entry");
            }
            if(String.IsNullOrEmpty(entry.Title))
            {
                throw new ArgumentException(Resources.Argument_EntryHasNoTitle, "entry");
            }

            string separator = SlugSettings.SeparatingCharacter;
            if(separator != "_" && separator != "." && separator != "-" && separator != string.Empty)
            {
                separator = DefaultWordSeparator;
            }

            string slug = RemoveNonWordCharacters(entry.Title);
            slug = RemoveTrailingPeriods(slug);

            if(SlugSettings.WordCountLimit > 0)
            {
                IEnumerable<string> words = slug.SplitIntoWords().Take(SlugSettings.WordCountLimit);
                IEnumerable<string> encodedWords = words.Select(word => ReplaceUnicodeCharacters(word));
                if(!String.IsNullOrEmpty(separator))
                {
                    slug = String.Join(separator, encodedWords.ToArray());
                    slug = slug.Trim(new[] { separator[0] });
                }
                else
                {
                    //special case for back compati
                    slug = slug.ToPascalCase();
                }
            }

            if(slug.IsNumeric())
            {
                slug = "n_" + slug;
            }
            slug = EnsureUniqueness(slug, SlugSettings.SeparatingCharacter);
            slug = FriendlyUrlSettings.TransformString(slug, SlugSettings.TextTransformation);

            return slug;
        }
        public static void CopyValuesTo(this Post post, Entry entry)
        {
            entry.Body = post.description;
            entry.Title = post.title;

            if (post.excerpt != null)
            {
                entry.Description = post.excerpt;
            }

            if (post.categories != null)
            {
                entry.Categories.AddRange(post.categories);
            }
            if (!string.IsNullOrEmpty(post.wp_slug))
            {
                entry.EntryName = post.wp_slug;
            }
        }