Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cast an Collection<x> to an IQueryable<x>

I am trying to set up a moq, but i am needing to create a fake IQueryable. i made a Collection but i am at a loss of how to cast that to an IQueryable.

Collection<DetailDataEntity> DetailDataEntityCollection = 
    new Collection<DetailDataEntity>();

DetailDataEntity DetailDataEntity = new DetailDataEntity();
DetailDataEntity.FeedTypeID = 1;
DetailDataEntityCollection.Add(DetailDataEntity);


_mockRepository.Setup(x => x.GetDetail(It.IsAny<Int32>(),
                                       It.IsAny<Enum.FeedTypeEnum.FeedType>())) 
               .Returns(DetailDataEntityCollection);
like image 216
Andy Avatar asked Feb 23 '23 05:02

Andy


1 Answers

Just call AsQueryable on your collection.

_mockRepository.Setup(x => x.GetDetail(It.IsAny<Int32>(), 
                                       It.IsAny<Enum.FeedTypeEnum.FeedType>()))
               .Returns(DetailDataEntityCollection.AsQueryable());
like image 84
Daniel Hilgarth Avatar answered Mar 03 '23 07:03

Daniel Hilgarth