I am trying to write a unit test for a method which takes an IQueryable collection.
How should I instantiate the collection in my unit test before I pass it to the method for test? This is the default code in my test
IQueryable<Item> Items = null; // TODO: Initialize to an appropriate value
And here is what I tried writing
IQueryable<Item> Items = new IQueryable<Item>; // TODO: Initialize to an appropriate value
Am I making a school boy error?
Well, you can use .AsQueryable()
on any typed collection/list/array, however IMO you cannot unit test this, as different query providers support different options/methods. You can only integration-test this. Any unit test (especially one using objects) does little or nothing to prove your system.
IQueryable seems to be an interface ( http://msdn.microsoft.com/en-us/library/system.linq.iqueryable.aspx ), shouldn't you try to instanciate a class that implements this interface instead (or maybe use a mock object for your test) ?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With