TypeMock with Linq to LLBLGen

Posts   
 
    
Meteor
User
Posts: 67
Joined: 06-Apr-2007
# Posted on: 11-Jan-2010 04:27:28   

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.

Meteor
User
Posts: 67
Joined: 06-Apr-2007
# Posted on: 11-Jan-2010 06:25:42   

This seems to work:

var fakeIOrderedEnumerable = from p in new[] { new PisOutputXmlEntity { XmlContent = "<test></test>" } } orderby x.XmlContent ascending select x;

var fakeIOrderedQueryable = from z in fakeIOrderedEnumerable.AsQueryable<PisOutputXmlEntity>() orderby z.DateAdded select z;

Isolate.WhenCalled(() => from p in fakeMetadata.PisOutputXml orderby p.DateAdded descending select p).WillReturn(fakeIOrderedQueryable);


Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 11-Jan-2010 10:27:27   

Thanks for the feedback