Пример #1
0
        public void AddCommentToEntry_WithLanguage()
        {
            // Perform this test in master DB as comments get created there
            var db = Sitecore.Configuration.Factory.GetDatabase("master");

            ID germanCommentId = null;

            try
            {
                var germanComment = new Sitecore.Modules.WeBlog.Model.Comment()
                {
                    AuthorEmail = "*****@*****.**",
                    AuthorName  = "german commentor",
                    Text        = "My German Comment"
                };

                germanComment.Fields[Sitecore.Modules.WeBlog.Constants.Fields.IpAddress] = "127.0.0.1";
                germanComment.Fields[Sitecore.Modules.WeBlog.Constants.Fields.Website]   = "website";

                var language = Sitecore.Globalization.Language.Parse("de");

                germanCommentId = new Mod.CommentManager().AddCommentToEntry(m_entry12.ID, germanComment, language);

                var germanCommentItem = db.GetItem(germanCommentId, language);
                Assert.IsNotNull(germanCommentItem);

                // Ensure the item only contains a version in German
                Assert.AreEqual(1, germanCommentItem.Versions.Count);
                Assert.AreEqual("de", germanCommentItem.Versions[new Sitecore.Data.Version(1)].Language.Name);
            }
            finally
            {
                var webDb = Sitecore.Configuration.Factory.GetDatabase("web");

                if (germanCommentId != (ID)null)
                {
                    var commentItem = db.GetItem(germanCommentId);
                    if (commentItem != null)
                    {
                        using (new SecurityDisabler())
                        {
                            commentItem.Delete();
                        }
                    }

                    commentItem = webDb.GetItem(germanCommentId);
                    if (commentItem != null)
                    {
                        using (new SecurityDisabler())
                        {
                            commentItem.Delete();
                        }
                    }
                }

                RebuildIndex();
            }
        }
Пример #2
0
        public void AddCommentToEntry()
        {
            // Perform this test in master DB as comments get created there
            var db = Sitecore.Configuration.Factory.GetDatabase("master");
            var blogSettings = new BlogHomeItem(m_blog1).BlogSettings;

            var originalCount = m_entry12.Axes.GetDescendants().Count(i => i.TemplateID == blogSettings.CommentTemplateID);
            ID commentId = null;

            try
            {
                var comment = new Sitecore.Modules.WeBlog.Model.Comment()
                {
                    AuthorEmail = "*****@*****.**",
                    AuthorName = "commentor",
                    Text = "My Comment"
                };

                comment.Fields[Sitecore.Modules.WeBlog.Constants.Fields.IpAddress] = "127.0.0.1";
                comment.Fields[Sitecore.Modules.WeBlog.Constants.Fields.Website] = "website";

                commentId = new Mod.CommentManager().AddCommentToEntry(m_entry12.ID, comment);
                var childCount = m_entry12.Axes.GetDescendants().Count(i => i.TemplateID == blogSettings.CommentTemplateID);

                Assert.IsTrue(commentId != ID.Null);
                Assert.AreEqual(originalCount + 1, childCount);

                var commentItem = db.GetItem(commentId);
                Assert.IsNotNull(commentItem);

                var commentAsComment = new Sitecore.Modules.WeBlog.Items.WeBlog.CommentItem(commentItem);
                Assert.AreEqual("*****@*****.**", commentAsComment.Email.Text);
                Assert.AreEqual("commentor", commentAsComment.Name.Text);
                Assert.AreEqual("127.0.0.1", commentAsComment.IPAddress.Text);
                Assert.AreEqual("website", commentAsComment.Website.Text);
                Assert.AreEqual("My Comment", StringUtil.RemoveTags(commentAsComment.Comment.Text));
            }
            finally
            {
                var webDb = Sitecore.Configuration.Factory.GetDatabase("web");
                if (commentId != (ID)null)
                {
                    var commentItem = db.GetItem(commentId);
                    if (commentItem != null)
                    {
                        using (new SecurityDisabler())
                        {
                            commentItem.Delete();
                        }
                    }

                    commentItem = webDb.GetItem(commentId);
                    if (commentItem != null)
                    {
                        using (new SecurityDisabler())
                        {
                            commentItem.Delete();
                        }
                    }
                }
            }
        }
Пример #3
0
        public void AddCommentToEntry_WithLanguage()
        {
            // Perform this test in master DB as comments get created there
            var db = Sitecore.Configuration.Factory.GetDatabase("master");

            ID germanCommentId = null;

            try
            {
                var germanComment = new Sitecore.Modules.WeBlog.Model.Comment()
                {
                    AuthorEmail = "*****@*****.**",
                    AuthorName = "german commentor",
                    Text = "My German Comment"
                };

                germanComment.Fields[Sitecore.Modules.WeBlog.Constants.Fields.IpAddress] = "127.0.0.1";
                germanComment.Fields[Sitecore.Modules.WeBlog.Constants.Fields.Website] = "website";

                germanCommentId = new Mod.CommentManager().AddCommentToEntry(m_entry12.ID, germanComment, Sitecore.Globalization.Language.Parse("de"));

                var germanCommentItem = db.GetItem(germanCommentId);
                Assert.IsNotNull(germanCommentItem);

                // Ensure the item only contains a version in German
                Assert.AreEqual(1, germanCommentItem.Versions.Count);
                Assert.AreEqual("de", germanCommentItem.Versions[new Sitecore.Data.Version(1)].Language.Name);
            }
            finally
            {
                var webDb = Sitecore.Configuration.Factory.GetDatabase("web");

                if (germanCommentId != (ID)null)
                {
                    var commentItem = db.GetItem(germanCommentId);
                    if (commentItem != null)
                    {
                        using (new SecurityDisabler())
                        {
                            commentItem.Delete();
                        }
                    }

                    commentItem = webDb.GetItem(germanCommentId);
                    if (commentItem != null)
                    {
                        using (new SecurityDisabler())
                        {
                            commentItem.Delete();
                        }
                    }
                }
            }
        }
Пример #4
0
        public void AddCommentToEntry()
        {
            // Perform this test in master DB as comments get created there
            var db           = Sitecore.Configuration.Factory.GetDatabase("master");
            var blogSettings = new BlogHomeItem(m_blog1).BlogSettings;

            var originalCount = m_entry12.Axes.GetDescendants().Count(i => i.TemplateID == blogSettings.CommentTemplateID);
            ID  commentId     = null;

            try
            {
                var comment = new Sitecore.Modules.WeBlog.Model.Comment()
                {
                    AuthorEmail = "*****@*****.**",
                    AuthorName  = "commentor",
                    Text        = "My Comment"
                };

                comment.Fields[Sitecore.Modules.WeBlog.Constants.Fields.IpAddress] = "127.0.0.1";
                comment.Fields[Sitecore.Modules.WeBlog.Constants.Fields.Website]   = "website";

                commentId = new Mod.CommentManager().AddCommentToEntry(m_entry12.ID, comment);
                var childCount = m_entry12.Axes.GetDescendants().Count(i => i.TemplateID == blogSettings.CommentTemplateID);

                Assert.IsTrue(commentId != ID.Null);
                Assert.AreEqual(originalCount + 1, childCount);

                var commentItem = db.GetItem(commentId);
                Assert.IsNotNull(commentItem);

                var commentAsComment = new Sitecore.Modules.WeBlog.Items.WeBlog.CommentItem(commentItem);
                Assert.AreEqual("*****@*****.**", commentAsComment.Email.Text);
                Assert.AreEqual("commentor", commentAsComment.Name.Text);
                Assert.AreEqual("127.0.0.1", commentAsComment.IPAddress.Text);
                Assert.AreEqual("website", commentAsComment.Website.Text);
                Assert.AreEqual("My Comment", StringUtil.RemoveTags(commentAsComment.Comment.Text));
            }
            finally
            {
                var webDb = Sitecore.Configuration.Factory.GetDatabase("web");
                if (commentId != (ID)null)
                {
                    var commentItem = db.GetItem(commentId);
                    if (commentItem != null)
                    {
                        using (new SecurityDisabler())
                        {
                            commentItem.Delete();
                        }
                    }

                    commentItem = webDb.GetItem(commentId);
                    if (commentItem != null)
                    {
                        using (new SecurityDisabler())
                        {
                            commentItem.Delete();
                        }
                    }
                }
            }
        }