public static IQueryable <TEntity> BuildMock <TEntity>(this IQueryable <TEntity> data) where TEntity : class { var mock = Substitute.For <IQueryable <TEntity>, IAsyncEnumerable <TEntity> > (); var enumerable = new TestAsyncEnumerable <TEntity>(data); ((IAsyncEnumerable <TEntity>)mock).GetEnumerator().Returns(enumerable.GetEnumerator()); mock.Provider.Returns(enumerable); mock.Expression.Returns(data?.Expression); mock.ElementType.Returns(data?.ElementType); mock.GetEnumerator().Returns(data?.GetEnumerator()); return(mock); }
public static IQueryable <TEntity> BuildMock <TEntity>(this IQueryable <TEntity> data) where TEntity : class { var mock = A.Fake <IQueryable <TEntity> >(d => d.Implements <IAsyncEnumerable <TEntity> >().Implements <IQueryable <TEntity> >()); var enumerable = new TestAsyncEnumerable <TEntity>(data); A.CallTo(() => ((IAsyncEnumerable <TEntity>)mock).GetEnumerator()).Returns(enumerable.GetEnumerator()); A.CallTo(() => ((IQueryable <TEntity>)mock).Provider).Returns(enumerable); A.CallTo(() => ((IQueryable <TEntity>)mock).Expression).Returns(data?.Expression); A.CallTo(() => ((IQueryable <TEntity>)mock).ElementType).Returns(data?.ElementType); A.CallTo(() => ((IQueryable <TEntity>)mock).GetEnumerator()).Returns(data?.GetEnumerator()); return(mock); }