I am trying to mock a Linq query result, and need to create a fake collection of IOrderedQueryable<T> to return when the query is executed.
Can anyone suggest how I can create a collection of this type manually (so I don't have to hit the database)?
I am using SelfServicing . I tried using
PisOutputXmlCollection col =
new PisOutputCollection { new PisOutputXmlEntity { Xmlcontent = "<test></test>" } };
but the TypeMock function (
Isolate.WhenCalled(() => from p in fakeMetadata.PisOutputXml orderby p.DateAdded descending select p).WillReturn(col)
) expects IOrderedQueryable<PisOutputXmlEntity> and I can't cast type SD.LLBLGen.Pro.LinqSupportClasses.DataSource<PisOutputXmlEntity> to IOrderedQueryable<PisOutputXmlEntity>.
var fake = from p in new[] { new PisOutputXmlEntity { XmlContent = "<test></test>" } } orderby x.XmlContent ascending select x;
doesn't work either (cannot cast System.Linq.OrderedEnumerable to IOrderedQueryable).
There seems to be a lot of examples around on the net for simple selects, but not select with orderby - which results in OrderedQueryable.