public getRecentPosts ( string blogid, string username, string password, int numberOfPosts ) : Subtext.Framework.XmlRpc.Post[] | ||
blogid | string | |
username | string | |
password | string | |
numberOfPosts | int | |
return | Subtext.Framework.XmlRpc.Post[] |
public void GetPages_WithNumberOfPosts_ReturnsPostsInPages() { //arrange string hostname = UnitTestHelper.GenerateUniqueString(); Config.CreateBlog("", "username", "password", hostname, ""); UnitTestHelper.SetHttpContextWithBlogRequest(hostname, ""); BlogRequest.Current.Blog = Config.GetBlog(hostname, ""); Config.CurrentBlog.AllowServiceAccess = true; var urlHelper = new Mock<UrlHelper>(); urlHelper.Setup(u => u.EntryUrl(It.IsAny<Entry>())).Returns("/entry/whatever"); var subtextContext = new Mock<ISubtextContext>(); subtextContext.Setup(c => c.Blog).Returns(Config.CurrentBlog); //TODO: FIX!!! subtextContext.Setup(c => c.Repository).Returns(ObjectProvider.Instance()); subtextContext.Setup(c => c.ServiceLocator).Returns(new Mock<IServiceLocator>().Object); subtextContext.Setup(c => c.UrlHelper).Returns(urlHelper.Object); var api = new MetaWeblog(subtextContext.Object); Post[] posts = api.getRecentPosts(Config.CurrentBlog.Id.ToString(), "username", "password", 10); Assert.AreEqual(0, posts.Length); string category1Name = UnitTestHelper.GenerateUniqueString(); string category2Name = UnitTestHelper.GenerateUniqueString(); UnitTestHelper.CreateCategory(Config.CurrentBlog.Id, category1Name); UnitTestHelper.CreateCategory(Config.CurrentBlog.Id, category2Name); var entry = new Entry(PostType.Story); entry.Title = "Title 1"; entry.Body = "Blah"; entry.IsActive = true; entry.IncludeInMainSyndication = true; entry.DateCreated = entry.DateSyndicated = entry.DateModified = DateTime.ParseExact("1975/01/23", "yyyy/MM/dd", CultureInfo.InvariantCulture); UnitTestHelper.Create(entry); entry = new Entry(PostType.Story); entry.IncludeInMainSyndication = true; entry.Title = "Title 2"; entry.Body = "Blah1"; entry.IsActive = true; entry.DateCreated = entry.DateSyndicated = entry.DateModified = DateTime.ParseExact("1976/05/25", "yyyy/MM/dd", CultureInfo.InvariantCulture); UnitTestHelper.Create(entry); entry = new Entry(PostType.Story); entry.Categories.Add(category1Name); entry.Categories.Add(category2Name); entry.Title = "Title 3"; entry.IncludeInMainSyndication = true; entry.Body = "Blah2"; entry.IsActive = true; entry.DateCreated = entry.DateSyndicated = entry.DateModified = DateTime.ParseExact("1979/09/16", "yyyy/MM/dd", CultureInfo.InvariantCulture); UnitTestHelper.Create(entry); entry = new Entry(PostType.Story); entry.Title = "Title 4"; entry.IncludeInMainSyndication = true; entry.Body = "Blah3"; entry.IsActive = true; entry.DateCreated = entry.DateSyndicated = entry.DateModified = DateTime.ParseExact("2006/01/01", "yyyy/MM/dd", CultureInfo.InvariantCulture); entry.Categories.Add(category2Name); int entryId = UnitTestHelper.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); //act posts = api.getPages(Config.CurrentBlog.Id.ToString(), "username", "password", 2); //assert Assert.AreEqual(2, posts.Length); Assert.AreEqual(1, posts[0].categories.Length); Assert.AreEqual(2, posts[1].categories.Length); Assert.IsNotNull(posts[1].categories, "Expected our categories to be there."); Assert.AreEqual(enclosureUrl, posts[0].enclosure.Value.url); Assert.AreEqual(enclosureMimeType, posts[0].enclosure.Value.type); Assert.AreEqual(enclosureSize, posts[0].enclosure.Value.length); }
public void GetRecentPosts_ReturnsRecentPosts() { string hostname = UnitTestHelper.GenerateUniqueString(); var repository = new DatabaseObjectProvider(); repository.CreateBlog("", "username", "password", hostname, ""); UnitTestHelper.SetHttpContextWithBlogRequest(hostname, ""); Blog blog = repository.GetBlog(hostname, ""); BlogRequest.Current.Blog = blog; blog.AllowServiceAccess = true; var urlHelper = new Mock<BlogUrlHelper>(); urlHelper.Setup(u => u.EntryUrl(It.IsAny<Entry>())).Returns("/entry/whatever"); var subtextContext = new Mock<ISubtextContext>(); subtextContext.Setup(c => c.Blog).Returns(Config.CurrentBlog); //TODO: FIX!!! subtextContext.Setup(c => c.Repository).Returns(repository); subtextContext.SetupBlog(blog); subtextContext.Setup(c => c.UrlHelper).Returns(urlHelper.Object); subtextContext.Setup(c => c.ServiceLocator).Returns(new Mock<IDependencyResolver>().Object); var api = new MetaWeblog(subtextContext.Object); Post[] posts = api.getRecentPosts(Config.CurrentBlog.Id.ToString(), "username", "password", 10); Assert.AreEqual(0, posts.Length); string category1Name = UnitTestHelper.GenerateUniqueString(); string category2Name = UnitTestHelper.GenerateUniqueString(); UnitTestHelper.CreateCategory(Config.CurrentBlog.Id, category1Name); UnitTestHelper.CreateCategory(Config.CurrentBlog.Id, category2Name); var entry = new Entry(PostType.BlogPost); entry.Title = "Title 1"; entry.Body = "Blah"; entry.IsActive = true; entry.IncludeInMainSyndication = true; entry.DateCreatedUtc = entry.DatePublishedUtc = entry.DateModifiedUtc = DateTime.ParseExact("1975/01/23", "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime(); entry.Categories.Add(category1Name); UnitTestHelper.Create(entry); entry = new Entry(PostType.BlogPost); entry.IncludeInMainSyndication = true; entry.Title = "Title 2"; entry.Body = "Blah1"; entry.IsActive = true; entry.DateCreatedUtc = entry.DatePublishedUtc = entry.DateModifiedUtc = DateTime.ParseExact("1976/05/25", "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime(); entry.Categories.Add(category1Name); entry.Categories.Add(category2Name); UnitTestHelper.Create(entry); entry = new Entry(PostType.BlogPost); entry.Title = "Title 3"; entry.IncludeInMainSyndication = true; entry.Body = "Blah2"; entry.IsActive = true; entry.DateCreatedUtc = entry.DatePublishedUtc = entry.DateModifiedUtc = DateTime.ParseExact("1979/09/16", "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime(); UnitTestHelper.Create(entry); entry = new Entry(PostType.BlogPost); entry.Title = "Title 4"; entry.IncludeInMainSyndication = true; entry.Body = "Blah3"; entry.IsActive = true; entry.DateCreatedUtc = entry.DatePublishedUtc = entry.DateModifiedUtc = DateTime.ParseExact("2006/01/01", "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime(); entry.Categories.Add(category2Name); int entryId = UnitTestHelper.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); repository.Create(enc); posts = api.getRecentPosts(Config.CurrentBlog.Id.ToString(), "username", "password", 10); Assert.AreEqual(4, posts.Length, "Expected 4 posts"); Assert.AreEqual(1, posts[3].categories.Length, "Expected our categories to be there."); Assert.AreEqual(2, posts[2].categories.Length, "Expected our categories to be there."); Assert.IsNotNull(posts[1].categories, "Expected our categories to be there."); Assert.AreEqual(1, posts[0].categories.Length, "Expected our categories to be there."); Assert.AreEqual(category1Name, posts[3].categories[0], "The category returned by the MetaBlogApi is wrong."); Assert.AreEqual(category2Name, posts[0].categories[0], "The category returned by the MetaBlogApi is wrong."); Assert.AreEqual(enclosureUrl, posts[0].enclosure.Value.url, "Not what we expected for the enclosure url."); Assert.AreEqual(enclosureMimeType, posts[0].enclosure.Value.type, "Not what we expected for the enclosure mimetype."); Assert.AreEqual(enclosureSize, posts[0].enclosure.Value.length, "Not what we expected for the enclosure size."); }
public void GetRecentPostsReturnsRecentPosts() { string hostname = UnitTestHelper.GenerateRandomString(); Assert.IsTrue(Config.CreateBlog("", "username", "password", hostname, "")); UnitTestHelper.SetHttpContextWithBlogRequest(hostname, ""); Config.CurrentBlog.AllowServiceAccess = true; MetaWeblog api = new MetaWeblog(); Post[] posts = api.getRecentPosts(Config.CurrentBlog.Id.ToString(), "username", "password", 10); Assert.AreEqual(0, posts.Length); 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.IncludeInMainSyndication = true; entry.DateCreated = entry.DateSyndicated = entry.DateModified = DateTime.ParseExact("1975/01/23", "yyyy/MM/dd", CultureInfo.InvariantCulture); entry.Categories.Add(category1Name); Entries.Create(entry); entry = new Entry(PostType.BlogPost); entry.IncludeInMainSyndication = true; entry.Title = "Title 2"; entry.Body = "Blah1"; entry.IsActive = true; entry.DateCreated = entry.DateSyndicated = entry.DateModified = DateTime.ParseExact("1976/05/25", "yyyy/MM/dd", CultureInfo.InvariantCulture); entry.Categories.Add(category1Name); entry.Categories.Add(category2Name); Entries.Create(entry); entry = new Entry(PostType.BlogPost); entry.Title = "Title 3"; entry.IncludeInMainSyndication = true; entry.Body = "Blah2"; entry.IsActive = true; entry.DateCreated = entry.DateSyndicated = entry.DateModified = DateTime.ParseExact("1979/09/16", "yyyy/MM/dd", CultureInfo.InvariantCulture); Entries.Create(entry); entry = new Entry(PostType.BlogPost); entry.Title = "Title 4"; entry.IncludeInMainSyndication = true; entry.Body = "Blah3"; entry.IsActive = true; entry.DateCreated = entry.DateSyndicated = entry.DateModified = DateTime.ParseExact("2006/01/01", "yyyy/MM/dd", CultureInfo.InvariantCulture); entry.Categories.Add(category2Name); 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); posts = api.getRecentPosts(Config.CurrentBlog.Id.ToString(), "username", "password", 10); Assert.AreEqual(4, posts.Length, "Expected 4 posts"); Assert.AreEqual(1, posts[3].categories.Length, "Expected our categories to be there."); Assert.AreEqual(2, posts[2].categories.Length, "Expected our categories to be there."); Assert.IsNull(posts[1].categories, "Expected our categories to be there."); Assert.AreEqual(1, posts[0].categories.Length, "Expected our categories to be there."); Assert.AreEqual(category1Name, posts[3].categories[0], "The category returned by the MetaBlogApi is wrong."); Assert.AreEqual(category2Name, posts[0].categories[0], "The category returned by the MetaBlogApi is wrong."); Assert.AreEqual(enclosureUrl, posts[0].enclosure.url, "Not what we expected for the enclosure url."); Assert.AreEqual(enclosureMimeType, posts[0].enclosure.type, "Not what we expected for the enclosure mimetype."); Assert.AreEqual(enclosureSize, posts[0].enclosure.length, "Not what we expected for the enclosure size."); }