public newPost ( string blogid, string username, string password, Subtext.Framework.XmlRpc.Post post, bool publish ) : string | ||
blogid | string | The blogid. |
username | string | The username. |
password | string | The password. |
post | Subtext.Framework.XmlRpc.Post | The post. |
publish | bool | if set to |
return | string |
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 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()); }
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 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 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 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 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); }