public void CreateWelcomeContent_CreatesIntroArticle()
        {
            // arrange
            var   installationManager = new InstallationManager(new Mock <IInstaller>().Object, null);
            var   repository          = new Mock <ObjectRepository>();
            var   entryPublisher      = new Mock <IEntryPublisher>();
            Entry article             = null;

            entryPublisher.Setup(p => p.Publish(It.Is <Entry>(e => e.PostType == PostType.Story))).Callback <Entry>(e => article = e);
            var urlHelper = new Mock <BlogUrlHelper>();

            urlHelper.Setup(u => u.AdminUrl("articles")).Returns("/admin/articles/default.aspx");
            var context = new Mock <ISubtextContext>();

            context.SetupUrlHelper(urlHelper);
            context.Setup(c => c.Repository).Returns(repository.Object);
            var blog = new Blog {
                Id = 123, Author = "TestAuthor"
            };

            // act
            installationManager.CreateWelcomeContent(context.Object, entryPublisher.Object, blog);

            // assert
            Assert.AreEqual(article.Title, "Welcome to Subtext!");
            Assert.Contains(article.Body, @"<a href=""/admin/articles/");
            Assert.IsTrue(!article.Body.Contains(@"<a href=""{0}"));
        }
        public void CreateWelcomeContent_CreatesIntroComment()
        {
            // arrange
            var installationManager = new InstallationManager(new Mock <IInstaller>().Object, null);
            var repository          = new Mock <ObjectRepository>();
            var entryPublisher      = new Mock <IEntryPublisher>();
            var urlHelper           = new Mock <BlogUrlHelper>();

            urlHelper.Setup(u => u.AdminUrl("feedback")).Returns("/admin/feedback/default.aspx");
            var context = new Mock <ISubtextContext>();

            context.SetupUrlHelper(urlHelper);
            context.Setup(c => c.Repository).Returns(repository.Object);
            var blog = new Blog {
                Id = 123, Author = "TestAuthor"
            };
            FeedbackItem comment = null;

            repository.Setup(r => r.Create(It.IsAny <FeedbackItem>())).Callback <FeedbackItem>(c => comment = c);

            // act
            installationManager.CreateWelcomeContent(context.Object, entryPublisher.Object, blog);

            // assert
            Assert.IsTrue(comment.Approved);
            Assert.AreEqual(comment.Title, "re: Welcome to Subtext!");
            Assert.Contains(comment.Body, @"<a href=""/admin/feedback/");
            Assert.IsTrue(!comment.Body.Contains(@"<a href=""{1}"));
        }
        protected void btnQuickCreate_Click(object sender, EventArgs e)
        {
            var hostInfo = HostInfo ?? HostInfo.LoadHostInfoFromDatabase(Repository, true);

            // Create the blog_config record using default values
            // and the specified user info

            //Since the password is stored as a hash, let's not hash it again.
            const bool passwordAlreadyHashed = true;

            string subfolder = hostInfo.BlogAggregationEnabled ? "blog" : "";

            int blogId = Repository.CreateBlog("TEMPORARY BLOG NAME", hostInfo.HostUserName, hostInfo.Password,
                                               Request.Url.Host, subfolder, passwordAlreadyHashed);

            if (blogId > -1)
            {
                var blog = Repository.GetBlogById(blogId);

                BlogRequest.Current.Blog = blog;
                // Need to refresh the context now that we have a blog.
                SubtextContext = DependencyResolver.Current.GetService <ISubtextContext>();
                if (!String.IsNullOrEmpty(hostInfo.Email))
                {
                    blog.Email = hostInfo.Email;
                    Repository.UpdateConfigData(blog);
                }
                InstallationManager.CreateWelcomeContent(SubtextContext, EntryPublisher, Blog);


                //We probably should have creating the blog authenticate the user
                //automatically so this redirect doesn't require a login.
                InstallationManager.ResetInstallationStatusCache();
                Response.Redirect(Url.BlogUrl());
            }
            else
            {
                const string errorMessage = "I'm sorry, but we had a problem creating your initial "
                                            +
                                            "configuration. Please <a href=\"http://code.google.com/p/subtext/issues/\" title=\"Subtext at Google Code\">report "
                                            + "this issue</a> to the Subtext team.";

                throw new InvalidOperationException(errorMessage);
            }
        }
        public void CreateWelcomeContent_CreatesIntroBlogPostAndCategories()
        {
            // arrange
            var   installationManager = new InstallationManager(new Mock <IInstaller>().Object, null);
            var   repository          = new Mock <ObjectRepository>();
            var   entryPublisher      = new Mock <IEntryPublisher>();
            Entry entry = null;

            entryPublisher.Setup(p => p.Publish(It.Is <Entry>(e => e.PostType == PostType.BlogPost))).Callback <Entry>(e => entry = e);
            var urlHelper = new Mock <BlogUrlHelper>();

            urlHelper.Setup(u => u.AdminUrl("")).Returns("/admin/default.aspx");
            urlHelper.Setup(u => u.EntryUrl(It.Is <Entry>(e => e.PostType == PostType.Story))).Returns <Entry>(e => "/articles/" + e.EntryName + ".aspx");
            urlHelper.Setup(u => u.HostAdminUrl("default.aspx")).Returns("/hostadmin/default.aspx");
            var context = new Mock <ISubtextContext>();

            context.SetupUrlHelper(urlHelper);
            context.Setup(c => c.Repository).Returns(repository.Object);
            var blog = new Blog {
                Id = 123, Author = "TestAuthor"
            };

            // act
            installationManager.CreateWelcomeContent(context.Object, entryPublisher.Object, blog);

            // assert
            Assert.AreEqual(entry.Title, "Welcome to Subtext!");
            Assert.AreEqual(entry.EntryName, "welcome-to-subtext");
            Assert.Contains(entry.Body, @"<a href=""/admin/default.aspx");
            Assert.Contains(entry.Body, @"<a href=""/articles/welcome-to-subtext-article.aspx");
            Assert.Contains(entry.Body, @"<a href=""/hostadmin/default.aspx");
            Assert.IsTrue(entry.AllowComments);
            Assert.IsTrue(!entry.Body.Contains(@"<a href=""{0}"));
            Assert.IsTrue(!entry.Body.Contains(@"<a href=""{1}"));
            Assert.IsTrue(!entry.Body.Contains(@"<a href=""{2}"));
        }