c# - Get IQueryable from Moq mockset - Stack Overflow
stackoverflow.com › questions › 42414244Feb 23, 2017 · Get IQueryable from Moq mockset. I have tried following the guide using Entity Framework and Moq to mock my context to test my repository. I'm currently having problems testing my GetSingle query from my repository: public Customer GetSingle (int id, HotelBookingContext context = null, params Expression<Func<Customer, object>> [] navigationProperties) { using (var tempContext = context ?? new HotelBookingContext ()) { IQueryable<Customer> dbQuery = tempContext.Set<Customer> (); foreach ...
c# - Moq with IQueryable Extension Methods - Stack Overflow
stackoverflow.com › questions › 34034432Dec 2, 2015 · Func<IQueryable<Models.Campaign>, Expression<Func<Models.Campaign, object>>, IQueryable<Models.Campaign>> includeMethod = (query, expression) => { return query.Include(expression); }; List<Models.Campaign> allResults = null; using (var sut = new CampaignRepository(_moqContext.Object, includeMethod)) { allResults = sut.AllIncluding(o => o.Id, o => o.Name).OrderBy(o => o.Id).ToList(); }
Mocking classes that implement IQueryable with Moq
stackoverflow.com › questions › 7048511Feb 11, 2015 · Mocking classes that implement IQueryable with Moq. I spent an evening trying to mock an object that implements IQueryable: var items = new Item [] {}.AsQueryable (); var repo = new Mock<IRepo> (); repo.Setup (r => r.GetEnumerator ()).Returns (items.GetEnumerator ()); repo.Setup (r => r.Provider).Returns (items.Provider); repo.Setup (r => r.ElementType).Returns (items.ElementType); repo.Setup (r => r.Expression).Returns (items.Expression);