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);
}