Rhino Mocks存根表达式

时间:2012-12-20 01:22:40

标签: lambda expression rhino-mocks stub stubbing

我想使用以下签名来存根方法:

Product[] GetAllActive(Expression<Func<Product, bool>> predicate, bool asNoTracking = true, params Expression<Func<Product, object>>[] navigationProperties);

我正在使用Rhino Mocks,任何想法

由于

1 个答案:

答案 0 :(得分: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"
                           }
                   };);