I have a unit test that I am trying to write.
I have this section as part of a working version:
List<MyClass> queryResult = new List<MyClass>(){};
A.CallTo(() => _dataContext.GetAll<MyClass>()).Returns(queryResult.AsQueryable());
However, I would rather put something like "null" instead of "queryResult.AsQueryable()", Then there would be no need to create an empty list.
But GetAll will return a list empty or full by the looks of things. Therefore, null won't work.
Is there something like "List.Empty" that I can use instead?
Thanks
There are
Array.Empty<T>()andEnumerable.Empty<T>()that might work for you. Neither of them allocates a new object per-call (they are both backed by a staticT[]field on a generic class -EmptyArray<T>.ValueorEmptyEnumerable<T>.Instance, although these are both implementation details)