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."); }
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); }
public void CanUpdatePostWithEnclosure() { string hostname = UnitTestHelper.GenerateRandomString(); Assert.IsTrue(Config.CreateBlog("", "username", "password", hostname, "")); UnitTestHelper.SetHttpContextWithBlogRequest(hostname, ""); Config.CurrentBlog.AllowServiceAccess = true; 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); int entryId = Entries.Create(entry); string enclosureUrl = "http://perseus.franklins.net/hanselminutes_0107.mp3"; string enclosureMimeType = "audio/mp3"; long enclosureSize = 26707573; FrameworkEnclosure enc = UnitTestHelper.BuildEnclosure("<Digital Photography Explained (for Geeks) with Aaron Hockley/>", enclosureUrl, enclosureMimeType, entryId, enclosureSize, true, true); Enclosures.Create(enc); entry = Entries.GetEntry(entryId, PostConfig.None, true); Assert.IsNotNull(entry.Enclosure, "There should be a enclosure here."); MetaWeblog api = new MetaWeblog(); Post post = new Post(); post.title = "Title 2"; post.description = "Blah"; post.dateCreated = DateTime.Now; Enclosure postEnclosure = new Enclosure(); postEnclosure.url = "http://codeclimber.net.nz/podcast/mypodcastUpdated.mp3"; postEnclosure.type = "audio/mp3"; postEnclosure.length = 123456789; post.enclosure = postEnclosure; bool result = api.editPost(entryId.ToString(CultureInfo.InvariantCulture), "username", "password", post, true); entry = Entries.GetEntry(entryId, PostConfig.None, true); Assert.IsNotNull(entry.Enclosure, "Should have kept the enclosure."); Assert.AreEqual("http://codeclimber.net.nz/podcast/mypodcastUpdated.mp3", entry.Enclosure.Url, "Not the updated enclosure url."); }
public void NewPost_WithNullCategories_DoesNotTHrowException() { //arrange var blog = new Blog { Id = 42, UserName = "******", Password = "******", AllowServiceAccess = true, Host = "localhost" }; var subtextContext = new Mock<ISubtextContext>(); subtextContext.Setup(c => c.Blog).Returns(blog); Entry publishedEntry = null; var entryPublisher = new Mock<IEntryPublisher>(); entryPublisher.Setup(publisher => publisher.Publish(It.IsAny<Entry>())).Returns(42).Callback<Entry>( entry => publishedEntry = entry); var api = new MetaWeblog(subtextContext.Object, entryPublisher.Object); var post = new Post { categories = null, description = "A unit test", title = "A unit testing title", dateCreated = DateTime.UtcNow }; // act string result = api.newPost(blog.Id.ToString(CultureInfo.InvariantCulture), "username", "password", post, true); // assert int entryId = int.Parse(result); Assert.AreEqual(42, entryId); Assert.AreEqual(0, publishedEntry.Categories.Count, "Should not have added categories."); }
public void editPost_WithNoCategories_RemovesCategoriesFromEntry() { //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); var post = new Post { title = "Title 2", description = "Blah", categories = null, dateCreated = DateTime.UtcNow }; var metaWeblog = new MetaWeblog(subtextContext.Object, entryPublisher.Object); // act metaWeblog.editPost("123", "username", "password", post, true); // assert Assert.AreEqual(0, publishedEntry.Categories.Count, "We expected no category."); }
private string PostContent(string username, string password, ref Post post, bool publish, PostType postType) { Framework.BlogInfo info = Config.CurrentBlog; ValidateUser(username, password, info.AllowServiceAccess); Entry entry = new Entry(postType); entry.Author = info.Author; entry.Email = info.Email; entry.Body = post.description; entry.Title = post.title; entry.Description = string.Empty; //TODO: Figure out why this is here. // Probably means the poster forgot to set the date. DateTime dateTimeInPost = Config.CurrentBlog.TimeZone.ToLocalTime(post.dateCreated); var lastEntryDate = DbProvider.Instance().GetLatestEntryDate(); if (dateTimeInPost.Year >= 2003) { // this is an indication that we want to move the rest of the posts if (dateTimeInPost.AddHours(-1) <= Config.CurrentBlog.TimeZone.Now) { DbProvider.Instance().PushOtherPostsDatesAfter(dateTimeInPost); } entry.DateCreated = dateTimeInPost; entry.DateModified = dateTimeInPost; } else { if (lastEntryDate == null) // there is no next entry date { entry.DateCreated = Config.CurrentBlog.TimeZone.Now; } else if (lastEntryDate.Value.AddDays(1) < Config.CurrentBlog.TimeZone.Now) // the latest date it too far in the past { entry.DateCreated = Config.CurrentBlog.TimeZone.Now; } else { // noon the next day entry.DateCreated = lastEntryDate.Value.Date.AddDays(1).AddHours(12); entry.Body = "<blockquote>Originally posted at " + Config.CurrentBlog.TimeZone.Now.ToShortDateString() + "</blockquote>" + entry.Body; } entry.DateModified = entry.DateCreated; } if (post.categories != null) { entry.Categories.AddRange(post.categories); } if (!string.IsNullOrEmpty(post.wp_slug)) { entry.EntryName = post.wp_slug; } entry.PostType = postType; entry.IsActive = publish; if (publish) { entry.DateSyndicated = entry.DateCreated; } entry.AllowComments = true; entry.DisplayOnHomePage = true; entry.IncludeInMainSyndication = true; entry.IsAggregated = true; entry.SyndicateDescriptionOnly = false; int postID; try { postID = Entries.Create(entry); if (!string.IsNullOrEmpty(post.enclosure.url)) { Components.Enclosure enc = new Components.Enclosure(); enc.Url = post.enclosure.url; enc.MimeType = post.enclosure.type; enc.Size = post.enclosure.length; enc.EntryId = postID; Enclosures.Create(enc); } AddCommunityCredits(entry); } catch (Exception e) { throw new XmlRpcFaultException(0, e.Message + " " + e.StackTrace); } if (postID < 0) { throw new XmlRpcFaultException(0, "The post could not be added"); } return postID.ToString(CultureInfo.InvariantCulture); }
/// <summary> /// Creates a new post. The publish boolean is used to determine whether the item /// should be published or not. /// </summary> /// <param name="blogid">The blogid.</param> /// <param name="username">The username.</param> /// <param name="password">The password.</param> /// <param name="post">The post.</param> /// <param name="publish">if set to <c>true</c> [publish].</param> /// <returns></returns> public string newPost(string blogid, string username, string password, Post post, bool publish) { return PostContent(username, password, ref post, publish, PostType.BlogPost); }
public Post getPost(string postid, string username, string password) { Framework.BlogInfo info = Config.CurrentBlog; ValidateUser(username, password, info.AllowServiceAccess); Entry entry = Entries.GetEntry(Int32.Parse(postid), PostConfig.None, true); Post post = new Post(); post.link = entry.Url; post.description = entry.Body; post.dateCreated = entry.DateCreated; post.postid = entry.Id; post.title = entry.Title; post.permalink = entry.FullyQualifiedUrl.ToString(); post.categories = new string[entry.Categories.Count]; if (entry.HasEntryName) { post.wp_slug = entry.EntryName; } entry.Categories.CopyTo(post.categories, 0); return post; }
public int newPage(string blog_id, string username, string password, Post content, bool publish) { return Convert.ToInt32(PostContent(username, password, ref content, publish, PostType.Story)); }
public Post getPage(string blog_id, string page_id, string username, string password) { Blog info = Blog; ValidateUser(username, password, info.AllowServiceAccess); Entry entry = GetBlogPost(page_id); var post = new Post { link = Url.EntryUrl(entry).ToFullyQualifiedUrl(Blog).ToString(), description = entry.Body, excerpt = entry.Description ?? string.Empty, dateCreated = entry.DateCreated, postid = entry.Id, title = entry.Title, permalink = Url.EntryUrl(entry).ToFullyQualifiedUrl(Blog).ToString(), categories = new string[entry.Categories.Count] }; entry.Categories.CopyTo(post.categories, 0); if(entry.HasEntryName) { post.wp_slug = entry.EntryName; } if(entry.Enclosure != null) { post.enclosure = new Enclosure { length = (int)entry.Enclosure.Size, type = entry.Enclosure.MimeType, url = entry.Enclosure.Url }; } return post; }
private string PostContent(string username, string password, ref Post post, bool publish, PostType postType) { ValidateUser(username, password, Blog.AllowServiceAccess); var entry = new Entry(postType) {PostType = postType, IsActive = publish, Author = Blog.Author, Email = Blog.Email}; post.CopyValuesTo(entry); entry.AllowComments = true; entry.DisplayOnHomePage = true; DateTime dateTimeInPost = post.dateCreated != null ? post.dateCreated.Value : DateTime.UtcNow; // Store in the blog's timezone dateTimeInPost = Blog.TimeZone.FromUtc(dateTimeInPost); entry.DateCreated = entry.DateModified = Blog.TimeZone.Now; if(publish) { entry.DateSyndicated = dateTimeInPost; } entry.IncludeInMainSyndication = true; entry.IsAggregated = true; entry.SyndicateDescriptionOnly = false; int postId; try { //TODO: Review whether keywords should be true. postId = EntryPublisher.Publish(entry); if(Blog.TrackbacksEnabled) { NotificationServices.Run(entry, Blog, Url); } if(post.enclosure != null) { Components.Enclosure enclosure = post.enclosure.Value.CopyValuesToEnclosure(); enclosure.EntryId = postId; Repository.Create(enclosure); } AddCommunityCredits(entry); } catch(Exception e) { throw new XmlRpcFaultException(0, e.Message + " " + e.StackTrace); } if(postId < 0) { throw new XmlRpcFaultException(0, Resources.XmlRpcFault_AddPostFailed); } return postId.ToString(CultureInfo.InvariantCulture); }
public void UpdatingWithEnclosureAddNewEnclosure() { string hostname = UnitTestHelper.GenerateRandomString(); Assert.IsTrue(Config.CreateBlog("", "username", "password", hostname, "")); UnitTestHelper.SetHttpContextWithBlogRequest(hostname, ""); Config.CurrentBlog.AllowServiceAccess = true; 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); int entryId = Entries.Create(entry); Assert.IsNull(entry.Enclosure, "There should not be any enclosure here."); MetaWeblog api = new MetaWeblog(); Post post = new Post(); post.title = "Title 2"; post.description = "Blah"; post.dateCreated = DateTime.Now; Enclosure postEnclosure = new Enclosure(); postEnclosure.url = "http://codeclimber.net.nz/podcast/mypodcast.mp3"; postEnclosure.type = "audio/mp3"; postEnclosure.length = 123456789; post.enclosure = postEnclosure; bool result = api.editPost(entryId.ToString(CultureInfo.InvariantCulture), "username", "password", post, true); entry = Entries.GetEntry(entryId, PostConfig.None, true); Assert.IsNotNull(entry.Enclosure, "Should have created the enclosure as well."); Assert.AreEqual("http://codeclimber.net.nz/podcast/mypodcast.mp3", entry.Enclosure.Url, "Not the expected enclosure url."); Assert.AreEqual("audio/mp3", entry.Enclosure.MimeType, "Not the expected enclosure mimetype."); Assert.AreEqual(123456789, entry.Enclosure.Size, "Not the expected enclosure size."); }
public int editPage(string blog_id, string page_id, string username, string password, Post content, bool publish) { ValidateUser(username, password, Blog.AllowServiceAccess); Entry entry = GetBlogPost(page_id); if(entry != null) { entry.Author = Blog.Author; entry.Email = Blog.Email; entry.Body = content.description; entry.Title = content.title; entry.Description = content.excerpt ?? string.Empty; entry.IncludeInMainSyndication = true; if(content.categories != null) { entry.Categories.AddRange(content.categories); } entry.PostType = PostType.Story; entry.IsActive = publish; if(!string.IsNullOrEmpty(content.wp_slug)) { entry.EntryName = content.wp_slug; } entry.DateModified = Blog.TimeZone.Now; EntryPublisher.Publish(entry); } return Convert.ToInt32(page_id, CultureInfo.InvariantCulture); }
public void NewPostWithFutureDateSyndicatesInTheFuture() { string hostname = UnitTestHelper.GenerateRandomString(); Assert.IsTrue(Config.CreateBlog("", "username", "password", hostname, "")); UnitTestHelper.SetHttpContextWithBlogRequest(hostname, ""); Config.CurrentBlog.AllowServiceAccess = true; MetaWeblog api = new MetaWeblog(); Post post = new Post(); post.categories = null; post.description = "A unit test"; post.title = "A unit testing title"; post.dateCreated = DateTime.Now.AddDays(1); 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.IsTrue(entry.DateSyndicated > DateTime.Now.AddDays(.75)); Assert.IsTrue(entry.DateSyndicated <= DateTime.Now.AddDays(1)); }
public void NewPostWithEnclosureCreatesEntryWithEnclosure() { string hostname = UnitTestHelper.GenerateRandomString(); Assert.IsTrue(Config.CreateBlog("", "username", "password", hostname, "")); UnitTestHelper.SetHttpContextWithBlogRequest(hostname, ""); Config.CurrentBlog.AllowServiceAccess = true; MetaWeblog api = new MetaWeblog(); Post post = new Post(); post.categories = null; post.description = "A unit test"; post.title = "A unit testing title"; post.dateCreated = DateTime.Now; Enclosure postEnclosure = new Enclosure(); postEnclosure.url = "http://codeclimber.net.nz/podcast/mypodcast.mp3"; postEnclosure.type = "audio/mp3"; postEnclosure.length = 123456789; post.enclosure = postEnclosure; 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.IsNotNull(entry.Enclosure,"Should have created the enclosure as well."); Assert.AreEqual("http://codeclimber.net.nz/podcast/mypodcast.mp3", entry.Enclosure.Url,"Not the expected enclosure url."); Assert.AreEqual("audio/mp3", entry.Enclosure.MimeType, "Not the expected enclosure mimetype."); Assert.AreEqual(123456789, entry.Enclosure.Size,"Not the expected enclosure size."); }
public int newPage(string blog_id, string username, string password, Post content, bool publish) { return Convert.ToInt32(PostContent(username, password, ref content, publish, PostType.Story), CultureInfo.InvariantCulture); }
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 int editPage(string blog_id, string page_id, string username, string password, Post content, bool publish) { ValidateUser(username, password, Blog.AllowServiceAccess); Entry entry = GetBlogPost(page_id); if (entry != null) { entry.Author = Blog.Author; entry.Email = Blog.Email; entry.Body = content.description; entry.Title = content.title; entry.Description = content.excerpt ?? string.Empty; entry.IncludeInMainSyndication = true; if (content.categories != null) { entry.Categories.AddRange(content.categories); } entry.PostType = PostType.Story; entry.IsActive = publish; if (!string.IsNullOrEmpty(content.wp_slug)) { entry.EntryName = content.wp_slug; } EntryPublisher.Publish(entry); } return Convert.ToInt32(page_id, CultureInfo.InvariantCulture); }
public bool editPost(string postid, string username, string password, Post post, bool publish) { ValidateUser(username, password, Blog.AllowServiceAccess); Entry entry = GetBlogPost(postid); if(entry != null) { entry.Author = Blog.Author; entry.Email = Blog.Email; entry.Categories.Clear(); post.CopyValuesTo(entry); entry.IncludeInMainSyndication = true; entry.PostType = PostType.BlogPost; //User trying to change future dating. if(publish && post.dateCreated != null && Blog.TimeZone.IsInFuture(post.dateCreated.Value, TimeZoneInfo.Utc)) { entry.DateSyndicated = post.dateCreated.Value; } entry.IsActive = publish; entry.DateModified = Blog.TimeZone.Now; EntryPublisher.Publish(entry); if(entry.Enclosure == null) { if(post.enclosure != null) { Components.Enclosure enclosure = post.enclosure.Value.CopyValuesToEnclosure(); enclosure.EntryId = entry.Id; Repository.Create(enclosure); } } else // if(entry.Enclosure != null) { if(post.enclosure != null) { Components.Enclosure enclosure = entry.Enclosure; post.enclosure.Value.CopyValuesTo(enclosure); Repository.Update(enclosure); } else { Repository.DeleteEnclosure(entry.Enclosure.Id); } } } return true; }
public void EditPost_WithoutEnclosure_RemovesEnclosureFromEntry() { // arrange FrameworkEnclosure enclosure = UnitTestHelper.BuildEnclosure("<Digital Photography Explained (for Geeks) with Aaron Hockley/>", "http://example.com/foo.mp3", "audio/mp3", 123, 2650, true, true); enclosure.Id = 321; var entry = new Entry(PostType.BlogPost) { Title = "Title 1", Body = "Blah", IsActive = true, Enclosure = enclosure }; entry.DateCreatedUtc = entry.DatePublishedUtc = entry.DateModifiedUtc = DateTime.ParseExact("1975/01/23", "yyyy/MM/dd", CultureInfo.InvariantCulture); var subtextContext = new Mock<ISubtextContext>(); var blog = new Blog { Id = 999, Host = "localhost", AllowServiceAccess = true, UserName = "******", Password = "******" }; subtextContext.Setup(c => c.Blog).Returns(blog); subtextContext.Setup(c => c.Repository.GetEntry(It.IsAny<Int32>(), false, true)).Returns(entry); bool enclosureDeleted = false; subtextContext.Setup(c => c.Repository.DeleteEnclosure(321)).Callback(() => enclosureDeleted = true); var entryPublisher = new Mock<IEntryPublisher>(); entryPublisher.Setup(p => p.Publish(It.IsAny<Entry>())); var post = new Post { title = "Title 2", description = "Blah", dateCreated = DateTime.UtcNow }; var api = new MetaWeblog(subtextContext.Object, entryPublisher.Object); // act bool result = api.editPost("999", "username", "password", post, true); // assert Assert.IsTrue(enclosureDeleted); Assert.IsTrue(result); }
public Post getPost(string postid, string username, string password) { ValidateUser(username, password, Blog.AllowServiceAccess); Entry entry = GetBlogPost(postid); if(entry == null) { throw new XmlRpcFaultException(0, Resources.XmlRpcFault_CouldNotFindEntry); } var post = new Post { link = Url.EntryUrl(entry).ToFullyQualifiedUrl(Blog).ToString(), description = entry.Body, excerpt = entry.Description ?? string.Empty, dateCreated = entry.DateCreated, postid = entry.Id, title = entry.Title, permalink = Url.EntryUrl(entry).ToFullyQualifiedUrl(Blog).ToString(), categories = new string[entry.Categories.Count] }; if(entry.Enclosure != null) { post.enclosure = new Enclosure { length = (int)entry.Enclosure.Size, type = entry.Enclosure.MimeType, url = entry.Enclosure.Url }; } if(entry.HasEntryName) { post.wp_slug = entry.EntryName; } entry.Categories.CopyTo(post.categories, 0); return post; }
public void editPost_WithPostHavingDifferentCategoryThanEntry_UpdatesCategory() { // arrange var entry = new Entry(PostType.BlogPost) { Id = 12345, Title = "Title 1", Body = "Blah", IsActive = true }; entry.Categories.Add("Category1"); entry.DateCreatedUtc = entry.DatePublishedUtc = entry.DateModifiedUtc = DateTime.ParseExact("1975/01/23", "yyyy/MM/dd", CultureInfo.InvariantCulture); var subtextContext = new Mock<ISubtextContext>(); var blog = new Blog { Id = 999, Host = "localhost", AllowServiceAccess = true, UserName = "******", Password = "******" }; 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); var post = new Post { title = "Title 2", description = "Blah", categories = new[] { "Category2" }, dateCreated = DateTime.UtcNow }; var api = new MetaWeblog(subtextContext.Object, entryPublisher.Object); // act bool result = api.editPost("12345", "username", "password", post, true); // assert Assert.AreEqual(1, publishedEntry.Categories.Count); Assert.AreEqual("Category2", publishedEntry.Categories.First()); Assert.IsTrue(result); }
public bool editPost(string postid, string username, string password, Post post, bool publish) { Framework.BlogInfo info = Config.CurrentBlog; ValidateUser(username, password, info.AllowServiceAccess); Entry entry = Entries.GetEntry(Int32.Parse(postid), PostConfig.None, true); if (entry != null) { entry.Author = info.Author; entry.Email = info.Email; entry.Body = post.description; entry.Title = post.title; entry.Description = string.Empty; entry.IncludeInMainSyndication = true; entry.Categories.Clear(); if (post.categories != null) entry.Categories.AddRange(post.categories); entry.PostType = PostType.BlogPost; //User trying to change future dating. DateTime dateTimeInPost = Config.CurrentBlog.TimeZone.ToLocalTime(post.dateCreated); if (dateTimeInPost > Config.CurrentBlog.TimeZone.Now && publish) { entry.DateSyndicated = dateTimeInPost; } entry.IsActive = publish; entry.DateModified = Config.CurrentBlog.TimeZone.Now; int[] categoryIds = { }; if (entry.Categories.Count > 0) { categoryIds = Entries.GetCategoryIdsFromCategoryTitles(entry); } if (!string.IsNullOrEmpty(post.wp_slug)) { entry.EntryName = post.wp_slug; } Entries.Update(entry); Entries.SetEntryCategoryList(entry.Id, categoryIds); if (entry.Enclosure == null) { if (!string.IsNullOrEmpty(post.enclosure.url)) { Components.Enclosure enc = new Components.Enclosure(); enc.Url = post.enclosure.url; enc.MimeType = post.enclosure.type; enc.Size = post.enclosure.length; enc.EntryId = entry.Id; Enclosures.Create(enc); } } else { if (!string.IsNullOrEmpty(post.enclosure.url)) { Components.Enclosure enc = entry.Enclosure; enc.Url = post.enclosure.url; enc.MimeType = post.enclosure.type; enc.Size = post.enclosure.length; Enclosures.Update(enc); } else { Enclosures.Delete(entry.Enclosure.Id); } } } return false; }
public void NewPostWithEnclosureCreatesEntryWithEnclosure() { //arrange var blog = new Blog { Id = 42, UserName = "******", Password = "******", AllowServiceAccess = true, Host = "localhost" }; var subtextContext = new Mock<ISubtextContext>(); subtextContext.Setup(c => c.Blog).Returns(blog); FrameworkEnclosure publishedEnclosure = null; subtextContext.Setup(c => c.Repository.Create(It.IsAny<FrameworkEnclosure>())).Callback<FrameworkEnclosure>( enclosure => publishedEnclosure = enclosure); var entryPublisher = new Mock<IEntryPublisher>(); entryPublisher.Setup(publisher => publisher.Publish(It.IsAny<Entry>())).Returns(42); DateTime now = DateTime.UtcNow; DateTime utcNow = now.ToUniversalTime(); var api = new MetaWeblog(subtextContext.Object, entryPublisher.Object); var post = new Post(); post.categories = null; post.description = "A unit test"; post.title = "A unit testing title"; post.dateCreated = utcNow.AddDays(1); var postEnclosure = new Enclosure(); postEnclosure.url = "http://codeclimber.net.nz/podcast/mypodcast.mp3"; postEnclosure.type = "audio/mp3"; postEnclosure.length = 123456789; post.enclosure = postEnclosure; // act string result = api.newPost(blog.Id.ToString(CultureInfo.InvariantCulture), "username", "password", post, true); // assert Assert.IsNotNull(publishedEnclosure); Assert.AreEqual("http://codeclimber.net.nz/podcast/mypodcast.mp3", publishedEnclosure.Url); Assert.AreEqual("audio/mp3", publishedEnclosure.MimeType); Assert.AreEqual(123456789, publishedEnclosure.Size); }
public Post[] getRecentPosts(string blogid, string username, string password, int numberOfPosts) { ValidateUser(username, password, Config.CurrentBlog.AllowServiceAccess); ICollection<Entry> ec = Entries.GetRecentPosts(numberOfPosts, PostType.BlogPost, PostConfig.IsActive, true); //int i = 0; int count = ec.Count; Post[] posts = new Post[count]; int i = 0; foreach (Entry entry in ec) { Post post = new Post(); post.dateCreated = entry.DateCreated; post.description = entry.Body; post.link = entry.Url; post.permalink = entry.FullyQualifiedUrl.ToString(); post.title = entry.Title; post.postid = entry.Id.ToString(CultureInfo.InvariantCulture); post.userid = entry.Body.GetHashCode().ToString(CultureInfo.InvariantCulture); if (entry.HasEntryName) { post.wp_slug = entry.EntryName; } if (entry.Categories != null && entry.Categories.Count > 0) { post.categories = new string[entry.Categories.Count]; entry.Categories.CopyTo(post.categories, 0); } if (entry.Enclosure != null) { post.enclosure.length = (int)entry.Enclosure.Size; post.enclosure.url = entry.Enclosure.Url; post.enclosure.type = entry.Enclosure.MimeType; } posts[i] = post; i++; } return posts; }
public void newPost_WithCategory_CreatesEntryWithCategory() { //arrange var repository = new DatabaseObjectProvider(); var blog = new Blog { Id = 42, UserName = "******", Password = "******", AllowServiceAccess = true, Host = "localhost" }; var entryPublisher = new Mock<IEntryPublisher>(); Entry publishedEntry = null; entryPublisher.Setup(publisher => publisher.Publish(It.IsAny<Entry>())).Callback<Entry>(e => publishedEntry = e); var subtextContext = new Mock<ISubtextContext>(); subtextContext.Setup(c => c.Blog).Returns(blog); subtextContext.Setup(c => c.Repository).Returns(repository); subtextContext.Setup(c => c.ServiceLocator).Returns(new Mock<IDependencyResolver>().Object); var api = new MetaWeblog(subtextContext.Object, entryPublisher.Object); var post = new Post { categories = new[] { "CategoryA" }, description = "A unit test", title = "A unit testing title", dateCreated = DateTime.UtcNow }; //act api.newPost("42", "username", "password", post, true); //assert Assert.IsNotNull(publishedEntry); Assert.AreEqual(1, publishedEntry.Categories.Count); Assert.AreEqual("CategoryA", publishedEntry.Categories.First()); }
/// <summary> /// Creates a new post. The publish boolean is used to determine whether the item /// should be published or not. /// </summary> /// <param name="blogid">The blogid.</param> /// <param name="username">The username.</param> /// <param name="password">The password.</param> /// <param name="post">The post.</param> /// <param name="publish">if set to <c>true</c> [publish].</param> /// <returns></returns> public string newPost(string blogid, string username, string password, Post post, bool publish) { return PostContent(username, password, ref post, publish, PostType.BlogPost); }
public void NewPost_WithFutureDate_SyndicatesInTheFuture() { //arrange var blog = new Blog { Id = 42, UserName = "******", Password = "******", AllowServiceAccess = true, Host = "localhost" }; var subtextContext = new Mock<ISubtextContext>(); subtextContext.Setup(c => c.Blog).Returns(blog); Entry publishedEntry = null; var entryPublisher = new Mock<IEntryPublisher>(); entryPublisher.Setup(publisher => publisher.Publish(It.IsAny<Entry>())).Returns(42).Callback<Entry>( entry => publishedEntry = entry); DateTime now = DateTime.UtcNow; var api = new MetaWeblog(subtextContext.Object, entryPublisher.Object); var post = new Post(); post.categories = null; post.description = "A unit test"; post.title = "A unit testing title"; post.dateCreated = now.AddDays(1); // act string result = api.newPost(blog.Id.ToString(CultureInfo.InvariantCulture), "username", "password", post, true); // assert Assert.IsNotNull(publishedEntry); Assert.Greater(publishedEntry.DateSyndicated, now.AddDays(.75)); Assert.LowerEqualThan(publishedEntry.DateSyndicated, now.AddDays(1)); }
public int editPage(string blog_id, string page_id, string username, string password, Post content, bool publish) { Framework.BlogInfo info = Config.CurrentBlog; ValidateUser(username, password, info.AllowServiceAccess); Entry entry = Entries.GetEntry(Int32.Parse(page_id), PostConfig.None, true); if (entry != null) { entry.Author = info.Author; entry.Email = info.Email; entry.Body = content.description; entry.Title = content.title; entry.Description = string.Empty; entry.IncludeInMainSyndication = true; if (content.categories != null) entry.Categories.AddRange(content.categories); entry.PostType = PostType.Story; entry.IsActive = publish; if (!string.IsNullOrEmpty(content.wp_slug)) { entry.EntryName = content.wp_slug; } entry.DateModified = Config.CurrentBlog.TimeZone.Now; Entries.Update(entry); } return Convert.ToInt32(page_id); }
public void NewPost_WithFutureDate_SyndicatesInTheFuture() { //arrange var blog = new Blog { Id = 42, UserName = "******", Password = "******", AllowServiceAccess = true, Host = "localhost" }; var subtextContext = new Mock<ISubtextContext>(); subtextContext.Setup(c => c.Blog).Returns(blog); Entry publishedEntry = null; var entryPublisher = new Mock<IEntryPublisher>(); entryPublisher.Setup(publisher => publisher.Publish(It.IsAny<Entry>())).Returns(42).Callback<Entry>( entry => publishedEntry = entry); var utcNow = DateTime.UtcNow; var now = new DateTime(utcNow.Year, utcNow.Month, utcNow.Day, utcNow.Hour, utcNow.Minute, utcNow.Second, DateTimeKind.Unspecified); var api = new MetaWeblog(subtextContext.Object, entryPublisher.Object); var post = new Post { categories = null, description = "A unit test", title = "A unit testing title", dateCreated = now.AddDays(1) }; // act api.newPost(blog.Id.ToString(CultureInfo.InvariantCulture), "username", "password", post, true); // assert Assert.IsNotNull(publishedEntry); Assert.Greater(publishedEntry.DateSyndicated, now.AddDays(.75)); Assert.LowerEqualThan(publishedEntry.DateSyndicated, now.AddDays(1)); Assert.AreEqual(publishedEntry.DatePublishedUtc.Kind, DateTimeKind.Utc); }