Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public void CanInsertNewMetaTag(string content, string name, string httpEquiv, bool withEntry, string errMsg)
        {
            blog = UnitTestHelper.CreateBlogAndSetupContext();

            int? entryId = null;
            if(withEntry)
            {
                Entry e = UnitTestHelper.CreateEntryInstanceForSyndication("Steven Harman", "My Post", "Foo Bar Zaa!");
                entryId = UnitTestHelper.Create(e);
            }

            MetaTag mt = UnitTestHelper.BuildMetaTag(content, name, httpEquiv, blog.Id, entryId, DateTime.Now);

            // make sure there are no meta-tags for this blog in the data store
            ICollection<MetaTag> tags = MetaTags.GetMetaTagsForBlog(blog, 0, 100);
            Assert.AreEqual(0, tags.Count, "Should be zero MetaTags.");

            // add the meta-tag to the data store
            int tagId = MetaTags.Create(mt);

            tags = MetaTags.GetMetaTagsForBlog(blog, 0, 100);

            Assert.AreEqual(1, tags.Count, errMsg);

            MetaTag newTag = tags.First();

            // make sure all attributes of the meta-tag were written to the data store correctly.
            Assert.AreEqual(tagId, newTag.Id, "Wrong Id");
            Assert.AreEqual(mt.Content, newTag.Content, "Wrong content");
            Assert.AreEqual(mt.Name, newTag.Name, "wrong name attribute");
            Assert.AreEqual(mt.HttpEquiv, newTag.HttpEquiv, "Wrong http-equiv attriubte");
            Assert.AreEqual(mt.BlogId, newTag.BlogId, "Wrong blogId");
            Assert.AreEqual(mt.EntryId, newTag.EntryId, "Wrong entryId");
            Assert.AreEqual(mt.DateCreated.Date, newTag.DateCreated.Date, "Wrong created date");
        }
Ejemplo n.º 3
0
        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;
        }
Ejemplo n.º 4
0
        protected ICollection<LinkCategory> GetArchiveCategories(Blog blog)
        {
            var linkCategories = new List<LinkCategory>();

            // we want to make sure that the LinkCategory is NOT null before we add it to the collection.
            LinkCategory category = Repository.Links(CategoryType.PostCollection, blog, Url);
            if (category != null)
            {
                linkCategories.Add(category);
            }
            category = Repository.Links(CategoryType.StoryCollection, blog, Url);
            if (category != null)
            {
                linkCategories.Add(category);
            }
            category = Repository.ArchiveMonth(Url, blog);
            if (category != null)
            {
                linkCategories.Add(category);
            }
            category = Repository.Links(CategoryType.ImageCollection, blog, Url);
            if (category != null)
            {
                linkCategories.Add(category);
            }
            return linkCategories;
        }
Ejemplo n.º 5
0
        public void RequestNotMatchingAnyBlog_ButWithASingleBlogInSystemWithLocalHostButNotMatchingSubfolder_ReturnsUpdatesItsHostThenRedirectsToSubfolder()
        {
            //arrange
            var onlyBlog = new Blog { Host = "localhost", Subfolder = "sub" };
            var pagedCollection = new PagedCollection<Blog> { onlyBlog };
            pagedCollection.MaxItems = 1;

            var repository = new Mock<ObjectRepository>();
            repository.Setup(r => r.GetBlog("example.com", It.IsAny<string>())).Returns((Blog)null);
            repository.Setup(r => r.GetPagedBlogs(null, 0, It.IsAny<int>(), ConfigurationFlags.None)).Returns(
                pagedCollection);
            var appSettings = new NameValueCollection();
            appSettings.Add("AggregateEnabled", "false");
            var hostInfo = new HostInfo(appSettings);
            var service = new BlogLookupService(repository.Object, new LazyNotNull<HostInfo>(() => hostInfo));
            var blogRequest = new BlogRequest("example.com", string.Empty, new Uri("http://example.com/foo/bar"), false);

            //act
            BlogLookupResult result = service.Lookup(blogRequest);

            //assert
            Assert.IsNull(result.Blog);
            Assert.IsNotNull(result.AlternateUrl);
            Assert.AreEqual("http://example.com/sub/foo/bar", result.AlternateUrl.ToString());
            Assert.AreEqual("example.com", onlyBlog.Host);
            repository.Verify(r => r.UpdateBlog(It.IsAny<Blog>()));
        }
Ejemplo n.º 6
0
 public void GetReturnsZeroWhenNoMetaTagsExistForBlog()
 {
     var repository = new DatabaseObjectProvider();
     blog = UnitTestHelper.CreateBlogAndSetupContext();
     Assert.AreEqual(0, repository.GetMetaTagsForBlog(blog, 0, 100).Count,
                     "Shouldn't have found any MetaTags for this blog.");
 }
Ejemplo n.º 7
0
        public void CanGetHashCode()
        {
            var blog = new Blog();
            blog.Host = "http://subtextproject.com";
            blog.Subfolder = "blog";

            Assert.AreNotEqual(0, blog.GetHashCode());
        }
Ejemplo n.º 8
0
        public void CommentRssWriterProducesValidEmptyFeed()
        {
            var blogInfo = new Blog();
            blogInfo.Host = "localhost";
            blogInfo.Subfolder = "blog";
            blogInfo.Email = "*****@*****.**";
            blogInfo.RFC3229DeltaEncodingEnabled = true;
            blogInfo.Title = "My Blog Rulz";
            blogInfo.TimeZoneId = TimeZonesTest.PacificTimeZoneId;

            Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication(blogInfo, "haacked", "title of the post",
                                                                           "Body of the post.");
            entry.EntryName = "titleofthepost";
            entry.DateCreatedUtc =
                entry.DatePublishedUtc =
                entry.DateModifiedUtc = DateTime.ParseExact("2006/04/01", "yyyy/MM/dd", CultureInfo.InvariantCulture);

            var context = new Mock<ISubtextContext>();
            context.FakeSyndicationContext(blogInfo, "/", null);
            Mock<BlogUrlHelper> urlHelper = Mock.Get(context.Object.UrlHelper);
            urlHelper.Setup(url => url.EntryUrl(It.IsAny<Entry>())).Returns(
                "/blog/archive/2006/04/01/titleofthepost.aspx");

            var writer = new CommentRssWriter(new StringWriter(), new List<FeedbackItem>(), entry, context.Object);

            Assert.IsTrue(entry.HasEntryName, "This entry should have an entry name.");

            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>title of the post</title>" + Environment.NewLine
                              + indent(2) + @"<link>http://localhost/blog/archive/2006/04/01/titleofthepost.aspx</link>" +
                              Environment.NewLine
                              + indent(2) + @"<description>Body of the post.</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>title of the post</title>" + Environment.NewLine
                              + indent(3) + @"<url>http://localhost/images/RSS2Image.gif</url>" + Environment.NewLine
                              + indent(3) + @"<link>http://localhost/blog/archive/2006/04/01/titleofthepost.aspx</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);

            Assert.AreEqual(expected, writer.Xml);
        }
Ejemplo n.º 9
0
        public void CanSetFeedBurnerName()
        {
            var blog = new Blog();
            blog.RssProxyUrl = null;
            Assert.IsFalse(blog.RssProxyEnabled);

            blog.RssProxyUrl = "Subtext";
            Assert.IsTrue(blog.RssProxyEnabled);
        }
Ejemplo n.º 10
0
 public void SetHeight()
 {
     Unit test = 100;
     var blog = new Blog {Host = "localhost", Subfolder = "subfolder"};
     var subtextContext = new Mock<ISubtextContext>();
     subtextContext.Setup(c => c.Blog).Returns(blog);
     frtep.InitializeControl(subtextContext.Object);
     frtep.Height = test;
     Assert.AreEqual(test, frtep.Height);
 }
Ejemplo n.º 11
0
 public void SetText()
 {
     var blog = new Blog {Host = "localhost", Subfolder = "subfolder"};
     string test = "Lorem Ipsum";
     var subtextContext = new Mock<ISubtextContext>();
     subtextContext.Setup(c => c.Blog).Returns(blog);
     frtep.InitializeControl(subtextContext.Object);
     frtep.Text = test;
     Assert.AreEqual(test, frtep.Text);
     Assert.AreEqual(test, frtep.Xhtml);
 }
Ejemplo n.º 12
0
        public void CanGetLanguageAndLanguageCode()
        {
            var blog = new Blog();
            blog.Language = null;
            Assert.AreEqual("en-US", blog.Language, "By default, the language is en-US");
            Assert.AreEqual("en", blog.LanguageCode);

            blog.Language = "fr-FR";
            Assert.AreEqual("fr-FR", blog.Language, "The language should have changed.");
            Assert.AreEqual("fr", blog.LanguageCode);
        }
Ejemplo n.º 13
0
        public void CanTestForEquality()
        {
            var blog = new Blog();
            blog.Id = 12;
            Assert.IsFalse(blog.Equals(null), "Blog should not equal null");
            Assert.IsFalse(blog.Equals("Something Not A Blog"), "Blog should not equal a string");

            var blog2 = new Blog();
            blog2.Id = 12;
            Assert.IsTrue(blog.Equals(blog2));
        }
Ejemplo n.º 14
0
 public SubtextContext(Blog blog, RequestContext requestContext, BlogUrlHelper urlHelper, ObjectRepository repository,
                       IPrincipal user, ICache cache, IDependencyResolver serviceLocator)
 {
     Blog = blog;
     RequestContext = requestContext;
     UrlHelper = urlHelper;
     Repository = repository;
     User = user ?? requestContext.HttpContext.User;
     Cache = cache ?? new SubtextCache(requestContext.HttpContext.Cache);
     ServiceLocator = serviceLocator;
 }
Ejemplo n.º 15
0
        public void CanGetMetaTagsForBlog()
        {
            blog = UnitTestHelper.CreateBlogAndSetupContext();

            InsertNewMetaTag("Adding description meta tag", "description", null, DateTime.Now, blog.Id, null);
            InsertNewMetaTag("no-cache", null, "cache-control", DateTime.Now, blog.Id, null);

            ICollection<MetaTag> tags = MetaTags.GetMetaTagsForBlog(blog, 0, 100);

            Assert.AreEqual(2, tags.Count, "Should be two tags for this blog.");
        }
Ejemplo n.º 16
0
        public void Ctor_WithBlogHavingDuplicateCommentsEnabled_DoesNotChangeBlog()
        {
            // arrange
            var blog = new Blog { DuplicateCommentsEnabled = true };
            var repository = new Mock<ObjectRepository>();
            repository.Setup(r => r.UpdateBlog(blog)).Throws(new InvalidOperationException());

            // act
            new BlogImportSetup(blog, repository.Object);

            // assert
            Assert.IsTrue(blog.DuplicateCommentsEnabled);
        }
Ejemplo n.º 17
0
        public BlogMLBlog ConvertBlog(Blog blog)
        {
            var bmlBlog = new BlogMLBlog
            {
                Title = blog.Title,
                SubTitle = blog.SubTitle,
                RootUrl = Url.BlogUrl().ToFullyQualifiedUrl(blog).ToString(),
                DateCreated = blog.DateCreatedUtc
            };

            PopulateAuthors(blog, bmlBlog);
            PopulateExtendedProperties(blog, bmlBlog);

            return bmlBlog;
        }
Ejemplo n.º 18
0
        public void Ctor_WithBlogHavingDuplicateCommentsDisabled_EnablesDuplicateComments()
        {
            // arrange
            var blog = new Blog {DuplicateCommentsEnabled = false};
            var repository = new Mock<ObjectRepository>();
            bool updateCalled = false;
            repository.Setup(r => r.UpdateBlog(blog)).Callback(() => updateCalled = true);

            // act
            new BlogImportSetup(blog, repository.Object);

            // assert
            Assert.IsTrue(blog.DuplicateCommentsEnabled);
            Assert.IsTrue(updateCalled);
        }
Ejemplo n.º 19
0
        public void MergeLinkCategoriesIntoSingleLinkCategory_WithNoCategories_ReturnsNull()
        {
            // arrange
            var blog = new Blog { Host = "example.com" };

            var urlHelper = new Mock<BlogUrlHelper>();
            urlHelper.Setup(u => u.CategoryUrl(It.IsAny<Category>())).Returns("/");

            var links = new LinkCategory[0];

            // act
            var mergedLinkCategory = Transformer.MergeLinkCategoriesIntoSingleLinkCategory("Title", CategoryType.StoryCollection, links, urlHelper.Object, blog);

            // assert
            Assert.IsNull(mergedLinkCategory);
        }
Ejemplo n.º 20
0
        public void UpdatePassword_WithNonEmptyPassword_HashesPassword()
        {
            // Arrange
            var blog = new Blog { IsPasswordHashed = true };
            var context = new Mock<ISubtextContext>();
            context.Setup(c => c.Repository.UpdateBlog(blog));
            context.Setup(c => c.Blog).Returns(blog);
            var accountService = new AccountService(context.Object);

            // Act
            accountService.UpdatePassword("newPass");

            // Assert
            string expected = SecurityHelper.HashPassword("newPass");
            Assert.AreEqual(expected, blog.Password);
        }
Ejemplo n.º 21
0
        public void Ctor_WithAllNonNullArgs_SetsProperties()
        {
            //arrange
            var requestContext = new RequestContext(new Mock<HttpContextBase>().Object, new RouteData());
            var urlHelper = new UrlHelper(requestContext, new RouteCollection());
            ObjectProvider objectRepository = new Mock<ObjectProvider>().Object;
            var blog = new Blog();

            //act
            var subtextContext = new SubtextContext(blog, requestContext, urlHelper, objectRepository, null, null, null);

            //assert
            Assert.AreEqual(blog, subtextContext.Blog);
            Assert.AreEqual(urlHelper, subtextContext.UrlHelper);
            Assert.AreEqual(requestContext, subtextContext.RequestContext);
            Assert.AreEqual(objectRepository, subtextContext.Repository);
        }
Ejemplo n.º 22
0
        public void EmailCommentToBlogAuthor_WithBlogHavingNullEmail_DoesNotSendEmail()
        {
            //arrange
            var comment = new FeedbackItem(FeedbackType.Comment) {};
            var blog = new Blog {Email = string.Empty};
            var emailProvider = new Mock<EmailProvider>();
            var context = new Mock<ISubtextContext>();
            context.Setup(c => c.UrlHelper).Returns(new Mock<BlogUrlHelper>().Object);
            context.Setup(c => c.Blog).Returns(blog);
            var emailService = new EmailService(emailProvider.Object, new Mock<ITemplateEngine>().Object, context.Object);
            emailProvider.Setup(
                e => e.Send(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Throws(
                new Exception());

            //act
            emailService.EmailCommentToBlogAuthor(comment);
        }
Ejemplo n.º 23
0
        public static LinkCategory Links(CategoryType catType, Blog blog, UrlHelper urlHelper)
        {
            switch(catType)
            {
                case CategoryType.PostCollection:
                    return Transformer.BuildLinks(UIText.PostCollection, CategoryType.PostCollection, blog, urlHelper);

                case CategoryType.ImageCollection:
                    return Transformer.BuildLinks(UIText.ImageCollection, CategoryType.ImageCollection, blog, urlHelper);

                case CategoryType.StoryCollection:
                    return Transformer.BuildLinks(UIText.ArticleCollection, CategoryType.StoryCollection, blog, urlHelper);

                default:
                    Debug.Fail(String.Format(CultureInfo.InvariantCulture,
                                             "Invalid CategoryType: {0} via Subtext.Web.UI.UIData.Links", catType));
                    return null;
            }
        }
Ejemplo n.º 24
0
        public void WriteRsdWritesTheCorrectRSD()
        {
            //arrange
            var blog = new Blog();
            blog.Id = 8675309;
            blog.Subfolder = "sub";
            blog.Host = "example.com";

            var urlHelper = new Mock<UrlHelper>();
            urlHelper.Setup(u => u.BlogUrl()).Returns("/");
            urlHelper.Setup(u => u.MetaWeblogApiUrl(blog)).Returns(
                new Uri("http://example.com/sub/services/metablogapi.aspx"));

            var builder = new StringBuilder();
            XmlWriter writer = XmlWriter.Create(builder);
            var handler = new RsdHandler(null);

            //act
            handler.WriteRsd(writer, blog, urlHelper.Object);

            //assert
            var xml = new XmlDocument();
            Console.WriteLine(builder);
            xml.LoadXml(builder.ToString());

            var nsmgr = new XmlNamespaceManager(xml.NameTable);
            nsmgr.AddNamespace("rsd", "http://archipelago.phrasewise.com/rsd");

            XmlNode rootRsdNode = xml.SelectSingleNode("/rsd:rsd", nsmgr);
            Assert.IsNotNull(rootRsdNode, "Could not find the root RSD node.");
            Assert.AreEqual("1.0", rootRsdNode.Attributes["version"].InnerText,
                            "Expected the version attribute to be '1.0'");

            XmlNode engineNameNode = xml.SelectSingleNode("/rsd:rsd/rsd:service/rsd:engineName", nsmgr);
            Assert.IsNotNull(engineNameNode, "Could not find the engineName node.");
            Assert.AreEqual(engineNameNode.InnerText, "Subtext");
            XmlNode node = xml.SelectSingleNode("/rsd:rsd/rsd:service/rsd:apis/rsd:api[@name='MetaWeblog']", nsmgr);
            Assert.IsNotNull(node, "Could not find the metaweblog node.");
            Assert.AreEqual("http://example.com/sub/services/metablogapi.aspx", node.Attributes["apiLink"].Value,
                            "Api link is wrong");

            Assert.AreEqual("8675309", node.Attributes["blogID"].Value, "Blog Id is not set.");
        }
        public void ConvertBlog_WithSubtextBlog_ReturnsCorrespondingBlogMLBlog()
        {
            // arrange
            var blog = new Blog {Title = "Test Blog Title", SubTitle = "Test Blog Subtitle", Author = "Charles Dickens", Host = "example.com", ModerationEnabled = true};
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.Setup(c => c.Blog).Returns(blog);
            subtextContext.Setup(c => c.UrlHelper.BlogUrl()).Returns("/");
            var converter = new BlogMLExportMapper(subtextContext.Object);

            // act
            var blogMLBlog = converter.ConvertBlog(blog);

            // assert
            Assert.AreEqual("Test Blog Title", blogMLBlog.Title);
            Assert.AreEqual("Test Blog Subtitle", blogMLBlog.SubTitle);
            Assert.AreEqual("http://example.com/", blogMLBlog.RootUrl);
            Assert.AreEqual("Charles Dickens", blogMLBlog.Authors[0].Title);
            Assert.AreEqual(BlogMLBlogExtendedProperties.CommentModeration, blogMLBlog.ExtendedProperties[0].Key);
            Assert.AreEqual("Enabled", blogMLBlog.ExtendedProperties[0].Value);
        }
Ejemplo n.º 26
0
        public void MergeLinkCategoriesIntoSingleLinkCategory_WithMultipleCategories_ReturnsSingleCategoryWithLinkCollection()
        {
            // arrange
            var blog = new Blog {Host = "example.com"};

            var urlHelper = new Mock<BlogUrlHelper>();
            urlHelper.Setup(u => u.CategoryUrl(It.IsAny<Category>())).Returns("/");

            var links = new[]
            {
                new LinkCategory(1, "category 1"),
                new LinkCategory(2, "category 2"),
            };

            // act
            var mergedLinkCategory = Transformer.MergeLinkCategoriesIntoSingleLinkCategory("Title", CategoryType.StoryCollection, links, urlHelper.Object, blog);

            // assert
            Assert.AreEqual(2, mergedLinkCategory.Links.Count);
        }
Ejemplo n.º 27
0
        public void FullyQualifiedUrl_ReturnsCorrectUrl()
        {
            // arrange
            var urlHelper = new Mock<BlogUrlHelper>();
            var entry = new Entry(PostType.BlogPost)
            {
                Id = 123,
                EntryName = "post-slug"
            };
            var blog = new Blog {Host = "localhost"};
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.Setup(c => c.UrlHelper.EntryUrl(It.IsAny<Entry>())).Returns("/2009/01/23/post-slug.aspx");
            subtextContext.Setup(c => c.Blog).Returns(blog);

            // act
            var model = new EntryViewModel(entry, subtextContext.Object);

            // assert
            Assert.AreEqual(model.FullyQualifiedUrl, "http://localhost/2009/01/23/post-slug.aspx");
        }
Ejemplo n.º 28
0
        public void GetBlogPosts_WithBlogHavingPosts_ReturnsAllPosts()
        {
            // arrange
            var blog = new Blog
            {Title = "Irrelevant Title", SubTitle = "Test Blog Subtitle", Author = "Charles Dickens", Host = "example.com", ModerationEnabled = true};
            var posts = new PagedCollection<EntryStatsView> {new EntryStatsView { Title = "Test Post Title"}};
            var context = new Mock<ISubtextContext>();
            context.Setup(c => c.Blog).Returns(blog);
            context.Setup(c => c.UrlHelper.BlogUrl()).Returns("/");
            context.Setup(c => c.Repository.GetEntriesForExport(It.IsAny<int>() /*pageIndex*/, 100 /*pageSize*/)).Returns(posts);
            var converter = new Mock<IBlogMLExportMapper>();
            converter.Setup(c => c.ConvertEntry(It.IsAny<EntryStatsView>(), false /*embedAttachments*/)).Returns(new BlogMLPost { Title = "Test Post Title" });
            var source = new BlogMLSource(context.Object, converter.Object);

            // act
            var blogMLPosts = source.GetBlogPosts(false /*embedAttachments*/);

            // assert
            Assert.AreEqual("Test Post Title", blogMLPosts.ToList().First().Title);
        }
Ejemplo n.º 29
0
        public void CanAuthenticateAdmin()
        {
            // arrange
            var cookies = new HttpCookieCollection();
            var request = new Mock<HttpRequestBase>();
            request.Setup(r => r.Path).Returns("/whatever");
            request.Setup(r => r.Cookies).Returns(cookies);
            request.Setup(r => r.QueryString).Returns(new NameValueCollection());
            var httpContext = new Mock<HttpContextBase>();
            httpContext.Setup(c => c.Request).Returns(request.Object);
            httpContext.Setup(c => c.Response.Cookies).Returns(cookies);
            var blog = new Blog {UserName = "******", Password = "******", IsPasswordHashed = false};

            // act
            bool authenticated = httpContext.Object.Authenticate(blog, "the-username", "thePassword", true);

            // assert
            Assert.IsTrue(authenticated);
            HttpCookie cookie = request.Object.SelectAuthenticationCookie(blog);
            Assert.IsNotNull(cookie);
        }
Ejemplo n.º 30
0
        public void CanGetMetaTagsForEntry()
        {
            blog = UnitTestHelper.CreateBlogAndSetupContext();

            Entry e = UnitTestHelper.CreateEntryInstanceForSyndication("Steve-o", "Bar",
                                                                       "Steve is still rockin it... or is he?");
            UnitTestHelper.Create(e);

            InsertNewMetaTag("Adding description meta tag", "description", null, DateTime.Now, blog.Id, null);
            InsertNewMetaTag("no-cache", null, "cache-control", DateTime.Now, blog.Id, null);

            // insert a few entry specific tags
            InsertNewMetaTag("Yet Another MetaTag", "author", null, DateTime.Now, blog.Id, e.Id);
            InsertNewMetaTag("One more for good measure", "description", null, DateTime.Now, blog.Id, e.Id);
            InsertNewMetaTag("no-cache", null, "cache-control", DateTime.Now, blog.Id, e.Id);
            InsertNewMetaTag("Mon, 22 Jul 2022 11:12:01 GMT", null, "expires", DateTime.Now, blog.Id, e.Id);

            ICollection<MetaTag> tags = MetaTags.GetMetaTagsForEntry(e, 0, 100);

            Assert.AreEqual(4, tags.Count, "Should have found 4 MetaTags for this entry.");
        }
Ejemplo n.º 31
0
 public static IPagedCollection <MetaTag> GetMetaTagsForBlog(Blog blog, int pageIndex, int pageSize)
 {
     return(ObjectProvider.Instance().GetMetaTagsForBlog(blog, pageIndex, pageSize));
 }