public void Can_Return_Published_Posts_By_Category() { Initialize(true); using (var repository = new NHibernateBlogService()) { var category = new Category() { Name = "Test" }; for (int i = 0; i < 5; i++) { var post = DummyLivePost(); post.Categories.Add(category); repository.Save(post); } for (int i = 0; i < 5; i++) { var post = DummyLivePost(); post.IsPublished = false; post.Categories.Add(category); repository.Save(post); } repository.Save(category); } using (var repository = new NHibernateBlogService()) { Assert.AreEqual(10, repository.GetPostsByCategory(1).Count); Assert.AreEqual(5, repository.GetPublishedPostsByCategory(1).Count); } }
public void Can_Get_Posts_By_Category_Id() { Initialize(true); using (var repository = new NHibernateBlogService()) { var post = DummyLivePost(); var category = new Category() { Name = "Test" }; post.Categories.Add(category); repository.Save(post); repository.Save(category); repository.CommitChanges(); Assert.AreEqual(post, repository.GetPostsByCategory(category.Id).First()); } }