2009-09-23 53 views
0

我使用SubSonic 3,并使用ActiveRecord方法。我在我的控制器中有一个简单的查询:SubSonic GetPaged方法 - 单元测试中需要的不同索引

var posts = from p in Post.GetPaged(page ?? 0, 20) 
      orderby p.Published descending 
      select p; 

“page”变量被定义为一个可为空的int(int?)。

这里的问题,当我运行下面的测试,它工作正常,并通过:

[Test] 
    public void IndexWithNullPageShouldLoadFirstPageOfRecentPosts() 
    { 
     //act 
     var testPosts = new List<Post>() 
         { 
          new Post() {PostID = 1, BlogID = 1, Published = null, Body = "1"}, 
          new Post() {PostID = 2, BlogID = 1, Published = DateTime.Now, Body = "2"}, 
          new Post() {PostID = 3, BlogID = 1, Published = DateTime.Now.AddDays(1), Body = "3"} 
         }; 
     Post.Setup(testPosts); 

     //act 
     var result = controller.Index(null) as ViewResult; 

     //assert 
     Assert.IsNotNull(result); 
     var home = result.ViewData.Model as HomeViewModel; 
     Assert.IsInstanceOf(typeof(HomeViewModel), home, "Wrong ViewModel"); 
     Assert.AreEqual(3, home.Posts.Count()); 

     //make sure the sort worked correctly 
     Assert.AreEqual(3, home.Posts.ElementAt(0).PostID); 
     Assert.AreEqual(2, home.Posts.ElementAt(1).PostID); 
     Assert.AreEqual(1, home.Posts.ElementAt(2).PostID); 
    } 

然而,当我推出的网站,它不返回任何记录(是的,有记录在实时数据库中)。两种方法都将“页面”变量设置为空。我发现如果我将“GetPaged”方法中的索引更改为1而不是0,那么记录会在网站上返回......但是,只要我这样做 - 我的测试就不会再通过了。我见过的所有文档都显示GetPaged索引是基于零的......所以我在这里有点困惑。

任何想法?

感谢, 乍得

回答

0

这似乎是在GetPaged工作与ActiveRecord的方式中的错误/不一致。正如您已经计算出的那样,它使用ActiveRecord存储库中的基于1的索引而不是基于0的索引。您能否请您将此事记录为github