kvnallen
7/13/2017 - 8:05 PM

Code base for mock EF 6

Code base for mock EF 6

public static Mock<DbSet<T>> GetMockDbSet<T>( IQueryable<T> entities ) where T : class
{
    var mockSet = new Mock<DbSet<T>>();
    mockSet.As<IQueryable<T>>().Setup( m => m.Provider ).Returns( entities.Provider );
    mockSet.As<IQueryable<T>>().Setup( m => m.Expression ).Returns( entities.Expression );
    mockSet.As<IQueryable<T>>().Setup( m => m.ElementType ).Returns( entities.ElementType );
    mockSet.As<IQueryable<T>>().Setup( m => m.GetEnumerator() ).Returns( entities.GetEnumerator );
    return mockSet;
}