示例#1
0
        public void CanGetRecentImages()
        {
            //arrange
            UnitTestHelper.SetupBlog();
            var repository = new DatabaseObjectProvider();
            var category = new LinkCategory
            {
                BlogId = Config.CurrentBlog.Id,
                Description = "Whatever",
                IsActive = true,
                Title = "Whatever"
            };
            int categoryId = repository.CreateLinkCategory(category);

            var image = new Image
            {
                Title = "Title",
                CategoryID = categoryId,
                BlogId = Config.CurrentBlog.Id,
                FileName = "Foo",
                Height = 10,
                Width = 10,
                IsActive = true,
            };
            int imageId = repository.InsertImage(image);

            //act
            ICollection<Image> images = repository.GetImages(Config.CurrentBlog.Host, null, 10);

            //assert
            Assert.AreEqual(1, images.Count);
            Assert.AreEqual(imageId, images.First().ImageID);
        }
示例#2
0
 /// <summary>
 /// Creates a new <see cref="CategoryWriter"/> instance.
 /// </summary>
 public CategoryWriter(TextWriter writer, ICollection<Entry> ec, LinkCategory lc, Uri url,
                       ISubtextContext context)
     : base(writer, ec, NullValue.NullDateTime, false, context)
 {
     Category = lc;
     Url = url;
 }
示例#3
0
 public override int CreateLinkCategory(LinkCategory lc)
 {
     return _procedures.InsertCategory(lc.Title,
         lc.IsActive,
         BlogId,
         (int)lc.CategoryType,
         lc.Description ?? string.Empty);
 }
示例#4
0
        /// <summary>
        /// Converts a LinkCategoryCollection into a single LinkCategory with its own LinkCollection.
        /// </summary>
        public static LinkCategory MergeLinkCategoriesIntoSingleLinkCategory(string title, CategoryType catType,
                                                                             IEnumerable<LinkCategory> links,
                                                                             BlogUrlHelper urlHelper, Blog blog)
        {
            if (!links.IsNullOrEmpty())
            {
                var mergedLinkCategory = new LinkCategory { Title = title };

                var merged = from linkCategory in links
                             select GetLinkFromLinkCategory(linkCategory, catType, urlHelper, blog);
                mergedLinkCategory.Links.AddRange(merged);
                return mergedLinkCategory;
            }

            return null;
        }
        protected void lkbPost_Click(object sender, EventArgs e)
        {
            if(Page.IsValid)
            {
                var newCategory = new LinkCategory
                {
                    CategoryType = CategoryType,
                    Title = txbNewTitle.Text,
                    IsActive = ckbNewIsActive.Checked,
                    Description = txbNewDescription.Text
                };
                PersistCategory(newCategory);

                Response.Redirect(Request.RawUrl);
            }
        }
示例#6
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);
        }
示例#7
0
        protected void lkbPost_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                LinkCategory newCategory = new LinkCategory();
                newCategory.CategoryType = CategoryType;
                newCategory.Title = txbNewTitle.Text;
                newCategory.IsActive = ckbNewIsActive.Checked;
                newCategory.Description = txbNewDescription.Text;
                PersistCategory(newCategory);

                BindList();
                txbNewTitle.Text = string.Empty;
                ckbNewIsActive.Checked = Preferences.AlwaysCreateIsActive;
                txbNewDescription.Text = string.Empty;
            }
        }
示例#8
0
        public static ICollection<LinkCategory> GetLinkCategoriesByPostId(int postId)
        {
            var links = new List<Link>(ObjectProvider.Instance().GetLinkCollectionByPostId(postId));
            ICollection<LinkCategory> postCategories =
                ObjectProvider.Instance().GetCategories(CategoryType.PostCollection, true /* activeOnly */);
            var categories = new LinkCategory[postCategories.Count];
            postCategories.CopyTo(categories, 0);

            foreach(LinkCategory category in categories)
            {
                LinkCategory innerCategory = category;
                if(!links.Exists(link => innerCategory.Id == link.CategoryId))
                {
                    postCategories.Remove(category);
                }
            }
            return postCategories;
        }
示例#9
0
        private static Link GetLinkFromLinkCategory(LinkCategory linkCategory, CategoryType catType, BlogUrlHelper urlHelper, Blog blog)
        {
            var link = new Link { Title = linkCategory.Title };

            switch (catType)
            {
                case CategoryType.StoryCollection:
                    link.Url = urlHelper.CategoryUrl(linkCategory).ToFullyQualifiedUrl(blog).ToString();
                    break;

                case CategoryType.PostCollection:
                    link.Url = urlHelper.CategoryUrl(linkCategory).ToFullyQualifiedUrl(blog).ToString();
                    link.Rss = urlHelper.CategoryRssUrl(linkCategory);
                    break;

                case CategoryType.ImageCollection:
                    link.Url = urlHelper.GalleryUrl(linkCategory.Id).ToFullyQualifiedUrl(blog).ToString();
                    break;
            }
            link.NewWindow = false;
            return link;
        }
示例#10
0
 private void PersistCategory(LinkCategory category)
 {
     try
     {
         if (category.Id > 0)
         {
             Links.UpdateLinkCategory(category);
             this.Messages.ShowMessage(string.Format(System.Globalization.CultureInfo.InvariantCulture, "Category \"{0}\" was updated.", category.Title));
         }
         else
         {
             category.Id = Links.CreateLinkCategory(category);
             this.Messages.ShowMessage(string.Format(System.Globalization.CultureInfo.InvariantCulture, "Category \"{0}\" was added.", category.Title));
         }
     }
     catch(Exception ex)
     {
         this.Messages.ShowError(String.Format(Constants.RES_EXCEPTION, "TODO...", ex.Message));
     }
 }
示例#11
0
 public abstract int CreateLinkCategory(LinkCategory linkCategory);
示例#12
0
        public void getCategories_ReturnsCategoriesInRepository()
        {
            //arrange
            var blog = new Blog { AllowServiceAccess = true, Host = "localhost", UserName = "******", Password = "******" };
            var category = new LinkCategory
            {
                BlogId = blog.Id,
                IsActive = true,
                Description = "Test category",
                Title = "CategoryA",
                CategoryType = CategoryType.PostCollection,
                Id = 42
            };

            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.Setup(c => c.Blog).Returns(blog);
            subtextContext.Setup(c => c.UrlHelper.CategoryUrl(It.IsAny<LinkCategory>())).Returns("/Category/42.aspx");
            subtextContext.Setup(c => c.UrlHelper.CategoryRssUrl(It.IsAny<LinkCategory>())).Returns("/rss.aspx?catId=42");
            subtextContext.Setup(c => c.Repository.GetCategories(CategoryType.PostCollection, false)).Returns(new[] { category });
            subtextContext.Setup(c => c.ServiceLocator).Returns(new Mock<IDependencyResolver>().Object);
            var api = new MetaWeblog(subtextContext.Object);

            //act
            CategoryInfo[] categories = api.getCategories(blog.Id.ToString(), "username", "password");

            //assert
            Assert.AreEqual(1, categories.Length);
            Assert.AreEqual("http://localhost/Category/42.aspx", categories[0].htmlUrl);
            Assert.AreEqual("http://localhost/rss.aspx?catId=42", categories[0].rssUrl);
        }
示例#13
0
 static LinkCategory CreateCategory(string title, string description, CategoryType categoryType, bool isActive)
 {
     var linkCategory = new LinkCategory();
     linkCategory.BlogId = Config.CurrentBlog.Id;
     linkCategory.Title = title;
     linkCategory.Description = description;
     linkCategory.CategoryType = categoryType;
     linkCategory.IsActive = isActive;
     return linkCategory;
 }
示例#14
0
 public override bool UpdateLinkCategory(LinkCategory lc)
 {
     return DbProvider.Instance().UpdateCategory(lc);
 }
示例#15
0
 public void CanSetAndGetSimpleLinkCategoryProperties()
 {
     var category = new LinkCategory();
     UnitTestHelper.AssertSimpleProperties(category);
 }
示例#16
0
 /// <summary>
 /// Creates categories from the blog ml.
 /// </summary>
 /// <remarks>
 /// At this time, we only support PostCollection link categories.
 /// </remarks>
 /// <param name="blog"></param>
 public override IDictionary<string, string> CreateCategories(BlogMLBlog blog)
 {
     IDictionary<string, string> idMap = new Dictionary<string, string>();
     foreach (BlogMLCategory bmlCategory in blog.Categories)
     {
         LinkCategory category = new LinkCategory();
         category.BlogId = Config.CurrentBlog.Id;
         category.Title = bmlCategory.Title;
         category.Description = bmlCategory.Description;
         category.IsActive = bmlCategory.Approved;
         category.CategoryType = CategoryType.PostCollection;
         Links.CreateLinkCategory(category);
         idMap.Add(bmlCategory.ID, category.Title);
     }
     return idMap;
 }
示例#17
0
        protected void lkbPost_Click(object sender, EventArgs e)
        {
            var newCategory = new LinkCategory
            {
                CategoryType = CategoryType.ImageCollection,
                Title = txbNewTitle.Text,
                IsActive = ckbNewIsActive.Checked,
                Description = txbNewDescription.Text
            };
            PersistCategory(newCategory);

            BindList();
            txbNewTitle.Text = String.Empty;
            ckbNewIsActive.Checked = Preferences.AlwaysCreateIsActive;
        }
        public LinkCollectionTester()
        {
            LinkCategory category = new LinkCategory();
            category.BlogId = Config.CurrentBlog.Id;
            category.IsActive = true;
            category.Title = "Foobar";
            category.Description = "Unit Test";
            this.categoryId = Links.CreateLinkCategory(category);

            //Create a couple links that should be ignored because postId is not null.
            Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication("Phil", "title", "in great shape");
            int entryId = Entries.Create(entry);
            UnitTestHelper.CreateLinkInDb(this.categoryId, "A Forgettable Link", entryId, String.Empty);
            UnitTestHelper.CreateLinkInDb(this.categoryId, "Another Forgettable Link", entryId, String.Empty);
            UnitTestHelper.CreateLinkInDb(this.categoryId, "Another Forgettable Link", entryId, String.Empty);
        }
示例#19
0
 // REFACTOR: duplicate from category editor; generalize a la EntryEditor
 private void PersistCategory(LinkCategory category)
 {
     try
     {
         if(category.Id > 0)
         {
             Repository.UpdateLinkCategory(category);
             Messages.ShowMessage(string.Format(CultureInfo.InvariantCulture, Resources.Message_CategoryUpdated,
                                                category.Title));
         }
         else
         {
             category.Id = Links.CreateLinkCategory(category);
             Messages.ShowMessage(string.Format(CultureInfo.InvariantCulture, Resources.Message_CategoryAdded,
                                                category.Title));
         }
     }
     catch(Exception ex)
     {
         Messages.ShowError(String.Format(Constants.RES_EXCEPTION, "TODO...", ex.Message));
     }
 }
示例#20
0
 public override int CreateLinkCategory(LinkCategory lc)
 {
     return DbProvider.Instance().InsertCategory(lc);
 }
示例#21
0
 public override bool UpdateLinkCategory(LinkCategory category)
 {
     return _procedures.UpdateCategory(category.Id,
         category.Title,
         category.IsActive,
         (int)category.CategoryType,
         category.Description ?? string.Empty,
         BlogId);
 }
示例#22
0
        public void NewPostWithCategoryCreatesEntryWithCategory()
        {
            string hostname = UnitTestHelper.GenerateRandomString();
            Assert.IsTrue(Config.CreateBlog("", "username", "password", hostname, ""));
            UnitTestHelper.SetHttpContextWithBlogRequest(hostname, "");
            Config.CurrentBlog.AllowServiceAccess = true;

            LinkCategory category = new LinkCategory();
            category.IsActive = true;
            category.Description = "Test category";
            category.Title = "CategoryA";
            Links.CreateLinkCategory(category);

            MetaWeblog api = new MetaWeblog();
            Post post = new Post();
            post.categories = new string[] {"CategoryA"};
            post.description = "A unit test";
            post.title = "A unit testing title";
            post.dateCreated = DateTime.Now;

            string result = api.newPost(Config.CurrentBlog.Id.ToString(CultureInfo.InvariantCulture), "username", "password", post, true);
            int entryId = int.Parse(result);

            Entry entry = Entries.GetEntry(entryId, PostConfig.None, true);
            Assert.IsNotNull(entry, "Guess the entry did not get created properly.");
            Assert.AreEqual(1, entry.Categories.Count, "We expected one category. We didn't get what we expected.");
            Assert.AreEqual("CategoryA", entry.Categories[0], "The wrong category was created.");
        }
 public PagedEntryByCategoryCollectionTester()
 {
     LinkCategory category = new LinkCategory();
     category.BlogId = Config.CurrentBlog.Id;
     category.IsActive = true;
     category.Title = "Foobar";
     category.Description = "Unit Test";
     this.categoryId = Links.CreateLinkCategory(category);
 }
示例#24
0
 public static LinkCategory LoadLinkCategory(IDataReader reader)
 {
     LinkCategory lc = new LinkCategory(ReadInt32(reader, "CategoryID"), ReadString(reader, "Title"));
     lc.IsActive = (bool)reader["Active"];
     if(reader["CategoryType"] != DBNull.Value)
     {
         lc.CategoryType = (CategoryType)((byte)reader["CategoryType"]);
     }
     if(reader["Description"] != DBNull.Value)
     {
         lc.Description = ReadString(reader, "Description");
     }
     if (reader["BlogId"] != DBNull.Value)
     {
         lc.BlogId = ReadInt32(reader, "BlogId");
     }
     else
     {
         lc.BlogId = Config.CurrentBlog.Id;
     }
     return lc;
 }
示例#25
0
 public abstract bool UpdateLinkCategory(LinkCategory linkCategory);
示例#26
0
 //TODO: implement dateLastViewedFeedItemPublished
 //TODO: Implement useDeltaEncoding
 /// <summary>
 /// Creates a new <see cref="CategoryWriter"/> instance.
 /// </summary>
 /// <param name="ec">Ec.</param>
 /// <param name="lc">Lc.</param>
 /// <param name="url">URL.</param>
 public CategoryWriter(IList<Entry> ec, LinkCategory lc, string url)
     : base(ec, NullValue.NullDateTime, false)
 {
     this.Category = lc;
     this.Url = url;
 }
示例#27
0
        public int newCategory(string blogid, string username, string password, WordpressCategory category)
        {
            LinkCategory newCategory = new LinkCategory();
            newCategory.CategoryType = CategoryType.PostCollection;
            newCategory.Title = category.name;
            newCategory.IsActive = true;
            newCategory.Description = category.name;

            newCategory.Id = Links.CreateLinkCategory(newCategory);

            return newCategory.Id;
        }
示例#28
0
        public int newCategory(string blogid, string username, string password, WordpressCategory category)
        {
            var newCategory = new LinkCategory
            {
                CategoryType = CategoryType.PostCollection,
                Title = category.name,
                IsActive = true,
                Description = category.name
            };

            newCategory.Id = Repository.CreateLinkCategory(newCategory);

            return newCategory.Id;
        }
示例#29
0
        public static LinkCategory LoadLinkCategory(DataRow dr)
        {
            LinkCategory lc = new LinkCategory((int)dr["CategoryID"], (string)dr["Title"]);

            // Active cannot be null.
            lc.IsActive = (bool)dr["Active"];

            if(dr["CategoryType"] != DBNull.Value)
            {
                lc.CategoryType = (CategoryType)((byte)dr["CategoryType"]);
            }
            if(dr["Description"] != DBNull.Value)
            {
                lc.Description = (string)dr["Description"];
            }
            if (dr["BlogId"] != DBNull.Value)
            {
                lc.BlogId = (int)dr["BlogId"];
            }
            else
            {
                lc.BlogId = Config.CurrentBlog.Id;
            }
            return lc;
        }
示例#30
0
        public void WritingBlogMLWithEverythingWorks()
        {
            CreateBlogAndSetupContext();

            LinkCategory category = new LinkCategory();
            category.Title = "CategoryA";
            category.BlogId = Config.CurrentBlog.Id;
            category.CategoryType = CategoryType.PostCollection;
            category.IsActive = true;
            Links.CreateLinkCategory(category);

            //Add a few entries.
            Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication("phil", "blah blah", "full bodied goodness");
            entry.Categories.Add("CategoryA");
            Entries.Create(entry);

            //Add a comment.
            FeedbackItem comment = UnitTestHelper.CreateCommentInstance(entry.Id, "joe", "re: blah", UnitTestHelper.GenerateRandomString(), DateTime.Now);
            comment.FeedbackType = FeedbackType.Comment;
            FeedbackItem.Create(comment, null);
            FeedbackItem.Approve(comment);

            //Add a trackback.
            Trackback trackback = new Trackback(entry.Id, "blah", new Uri("http://example.com/"), "you", "your post is great" + UnitTestHelper.GenerateRandomString());
            FeedbackItem.Create(trackback, null);
            FeedbackItem.Approve(trackback);

            //setup provider
            // Not using BlogMlProvider.Instance() because we need to reset the state.
            SubtextBlogMLProvider provider = new SubtextBlogMLProvider();
            provider.ConnectionString = Config.ConnectionString;
            BlogMLWriter writer = BlogMLWriter.Create(provider);
            // TODO- BlogML 2.0
            //			writer.EmbedAttachments = false;

            //Note, once the next version of BlogML is released, we can cleanup some of this.
            StringBuilder builder = new StringBuilder();
            StringWriter textWriter = new StringWriter(builder);
            XmlTextWriter xml = new XmlTextWriter(textWriter);
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;
            settings.IndentChars = "  ";
            XmlWriter xmlWriter = XmlWriter.Create(xml);
            writer.Write(xmlWriter);

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(builder.ToString());
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
            nsmgr.AddNamespace("bml", "http://www.blogml.com/2006/09/BlogML");

            Console.WriteLine(doc.InnerXml);
            XmlNode postNode = doc.SelectSingleNode("bml:blog/bml:posts/bml:post[@id='1']", nsmgr);
            Assert.IsNotNull(postNode, "The post node is null");

            XmlNode firstPostCategoryNode = doc.SelectSingleNode("bml:blog/bml:posts/bml:post[@id='1']/bml:categories/bml:category", nsmgr);
            Assert.IsNotNull(firstPostCategoryNode, "Expected a category for the first post");

            XmlNode firstPostCommentNode = doc.SelectSingleNode("bml:blog/bml:posts/bml:post[@id='1']/bml:comments/bml:comment", nsmgr);
            Assert.IsNotNull(firstPostCommentNode, "Expected a comment for the first post");

            XmlNode firstPostTrackbackNode = doc.SelectSingleNode("bml:blog/bml:posts/bml:post[@id='1']/bml:trackbacks/bml:trackback", nsmgr);
            Assert.IsNotNull(firstPostTrackbackNode, "Expected a trackback for the first post");
        }