EntityFramework-Plus icon indicating copy to clipboard operation
EntityFramework-Plus copied to clipboard

Feature Request - Make it work with EnumerableQuery

Open mmoroni opened this issue 7 years ago • 1 comments

Being able to use EnumerableQuery, instead of a DbQuery / ObjectQuery, would make Unit Testing much much easier for me.

Let's say I have the following piece of code:

public void PriceRange(IQueryable<Product> products)
{
   int maxPrice = products.Max(x => x.Prices);
   int minPrice = products.Min(x => x.Prices);
   return maxPrice - minPrice;
}

When running that code, I would call this method using:

var ctx = new EntitiesContext();
var priceRange = PriceRange(ctx.Products);

When unit testing it, I would call this method using:

var products = new List<Product>
{
   new Product { Price = 10 },
   new Product { Price = 15 }
};
var priceRange = PriceRange(products.AsQueryable());
Assert.IsEqual(5, priceRange);

But, if I decide to use a FutureQuery, like this:

public void PriceRange(IQueryable<Product> products)
{
   var futureMaxPrice = products.DeferredMax(x => x.Prices).FutureValue<int>();
   var futureMinPrice = products.DeferredMin(x => x.Prices).FutureValue<int>();
   
   var maxPrice = futureMaxPrice.Value;
   var minPrice = futureMinPrice.Value;

   return maxPrice - minPrice;
}

Then I'm not able to Unit Test it anymore because IQueryable<Product> will be an EnumerableQuery and that's not supported.

mmoroni avatar Mar 14 '18 18:03 mmoroni

Hello @mmoroni ,

Thank you for reporting.

As I understand the purpose of this request, there is currently no plan to make it compatible with IEnumerable.

If you want to use our library for testing purpose without a database, try to use some library such as: http://entityframework-effort.net/

Best Regards,

Jonathan

JonathanMagnan avatar Mar 15 '18 20:03 JonathanMagnan