user3132547
user3132547

Reputation: 193

Mocking FirstOrDefault in rhino mocks

I'm trying to mock the following stuff:

_reportsRepo.Expect(x => x.Table.FirstOrDefault(s => s.MessageId == 1)).Return(new Report { Id = 1 });

but i get ArgumentNullException. Any ideas?

Upvotes: 1

Views: 475

Answers (1)

Sam Holder
Sam Holder

Reputation: 32946

I think you can just do something along these lines:

_reportsRepo.Expect(x => x.Table).Return(new []{Report { Id = 1 }});

depending on exactly what type Table is.

you can't mock FirstOrDefault instead you should mock the enumeration which it is returning so that it returns a collection which fulfils your requirements

Upvotes: 2

Related Questions