Stijn Van Antwerpen
Stijn Van Antwerpen

Reputation: 1986

How to set Expectation for Linq query

Using Rhino Mocks:

var list = MockRepository.GenerateMock<List<Foo>>();
list.Expect(e => e.Any(Arg<Func<Foo, bool>>.Is.Anything)).Return(false);

It throws

ArgumentNullException: Value cannot be null. Parameter name: predicate

How do I write this well?

Upvotes: 1

Views: 184

Answers (1)

Old Fox
Old Fox

Reputation: 8725

The method Any is an Extension method which means the method is a static method. You cannot fake static methods using Rhino Mocks.

It's a common mistake to put an expectation like this for asserting.

Actually you don't have to fake the List (It is a DS which means the behaviour won't impact the test), just create an instance of the real class and use it , then verify that the flow of empty list behave correctly.(do Assert on the things which should be happen)

Upvotes: 1

Related Questions