editPost() public method

public editPost ( string postid, string username, string password, Subtext.Framework.XmlRpc.Post post, bool publish ) : bool
postid string
username string
password string
post Subtext.Framework.XmlRpc.Post
publish bool
return bool
Esempio n. 1
0
        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.");
        }
Esempio n. 2
0
        public void editPost_WithEnclosure_AddsNewEnclosure()
        {
            //arrange
            FrameworkEnclosure enclosure = UnitTestHelper.BuildEnclosure("<Digital Photography Explained (for Geeks) with Aaron Hockley/>",
                                              "http://example.com/foo.mp3", "audio/mp3", 123, 26707573, true, true);
            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);
            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", dateCreated = DateTime.UtcNow };
            var postEnclosure = new Enclosure
            {
                url = "http://example.com/bar.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.IsNotNull(publishedEntry.Enclosure);
            Assert.AreEqual("http://example.com/bar.mp3", entry.Enclosure.Url);
            Assert.AreEqual("audio/mp3", entry.Enclosure.MimeType);
            Assert.AreEqual(123456789, entry.Enclosure.Size);
            Assert.IsTrue(result);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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.");
        }
Esempio n. 6
0
        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.");
        }
Esempio n. 7
0
        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.");
        }