2011-08-19 54 views
3

我想設置一個moq,但我需要創建一個假的IQueryable。我做了一個集合,但我不知道如何將它轉換爲IQueryable。如何投一個集合<x>到一個IQueryable <x>

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); 

回答

7

只需致電AsQueryable您的收藏。

_mockRepository.Setup(x => x.GetDetail(It.IsAny<Int32>(), 
             It.IsAny<Enum.FeedTypeEnum.FeedType>())) 
       .Returns(DetailDataEntityCollection.AsQueryable()); 
相關問題