Rhino Mocks存根表达式

4
我想要存根一个带有以下签名的方法:
Product[] GetAllActive(Expression<Func<Product, bool>> predicate, bool asNoTracking = true, params Expression<Func<Product, object>>[] navigationProperties);

我正在使用Rhino Mocks,有什么想法吗?
谢谢
1个回答

6
这个方法对我有用:
productService.Stub(
            p =>
            p.GetAllActive(
                Arg<Expression<Func<Product, bool>>>.Is.Anything, 
                Arg<bool>.Is.Anything, 
                Arg<Expression<Func<Product, object>>>.Is.Anything)).Return(new[]
                   {
                       new Product
                           {
                               Id = 1, 
                               Name = "Special one", 
                               ShortDescription = "This is product one"
                           }, 
                       new Product
                           {
                               Id = 2, 
                               Name = "Special two", 
                               ShortDescription = "This is product two"
                           }
                   };);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接