diff --git a/Source/EntityFramework.Extended/Extensions/FutureExtensions.cs b/Source/EntityFramework.Extended/Extensions/FutureExtensions.cs index 8b18a97..3f54261 100644 --- a/Source/EntityFramework.Extended/Extensions/FutureExtensions.cs +++ b/Source/EntityFramework.Extended/Extensions/FutureExtensions.cs @@ -30,7 +30,13 @@ public static FutureQuery Future(this IQueryable sour ObjectQuery sourceQuery = source.ToObjectQuery(); if (sourceQuery == null) + { + // Early return for test scenarios, here so it only slows down the error path + if (source is IFutureTestQueryable) + return new FutureQuery(source, null); + throw new ArgumentException("The source query must be of type ObjectQuery or DbQuery.", "source"); + } var futureContext = GetFutureContext(sourceQuery); var future = new FutureQuery(sourceQuery, futureContext.ExecuteFutureQueries); @@ -54,7 +60,13 @@ public static FutureCount FutureCount(this IQueryable source) ObjectQuery sourceQuery = source.ToObjectQuery(); if (sourceQuery == null) + { + // Early return for test scenarios, here so it only slows down the error path + if (source is IFutureTestQueryable) + return new FutureCount(source, null); + throw new ArgumentException("The source query must be of type ObjectQuery or DbQuery.", "source"); + } // create count expression var expression = Expression.Call( @@ -65,8 +77,6 @@ public static FutureCount FutureCount(this IQueryable source) // create query from expression using internal ObjectQueryProvider ObjectQuery countQuery = sourceQuery.CreateQuery(expression, typeof(int)); - if (countQuery == null) - throw new ArgumentException("The source query must be of type ObjectQuery or DbQuery.", "source"); var futureContext = GetFutureContext(sourceQuery); var future = new FutureCount(countQuery, futureContext.ExecuteFutureQueries); @@ -90,7 +100,13 @@ public static FutureValue FutureValue(this IQueryable var sourceQuery = source.ToObjectQuery(); if (sourceQuery == null) + { + // Early return for test scenarios, here so it only slows down the error path + if (source is IFutureTestQueryable) + return new FutureValue(source, null); + throw new ArgumentException("The source query must be of type ObjectQuery or DbQuery.", "source"); + } var methodExpr = selector.Body as MethodCallExpression; if (methodExpr == null || methodExpr.Arguments.Count == 0) @@ -131,14 +147,18 @@ public static FutureValue FutureFirstOrDefault(this IQueryable ObjectQuery sourceQuery = source.ToObjectQuery(); if (sourceQuery == null) + { + // Early return for test scenarios, here so it only slows down the error path + if (source is IFutureTestQueryable) + return new FutureValue(source, null); + throw new ArgumentException("The source query must be of type ObjectQuery or DbQuery.", "source"); + } // make sure to only get the first value IQueryable firstQuery = source.Take(1); ObjectQuery objectQuery = firstQuery.ToObjectQuery(); - if (objectQuery == null) - throw new ArgumentException("The source query must be of type ObjectQuery or DbQuery.", "source"); var futureContext = GetFutureContext(sourceQuery); var future = new FutureValue(objectQuery, futureContext.ExecuteFutureQueries); diff --git a/Source/EntityFramework.Extended/Future/FutureValue.cs b/Source/EntityFramework.Extended/Future/FutureValue.cs index 4e283b2..52f3874 100644 --- a/Source/EntityFramework.Extended/Future/FutureValue.cs +++ b/Source/EntityFramework.Extended/Future/FutureValue.cs @@ -10,7 +10,7 @@ namespace EntityFramework.Future /// The type for the future query. /// The following is an example of how to use FutureValue. /// t.Summary == "Test").Future(); @@ -20,7 +20,7 @@ namespace EntityFramework.Future /// ]]> /// /// - [DebuggerDisplay("IsLoaded={IsLoaded}, Value={UnderlingValue}")] + [DebuggerDisplay("IsLoaded={IsLoaded}, Value={UnderlyingValue}")] public class FutureValue : FutureQueryBase { private bool _hasValue; diff --git a/Source/EntityFramework.Extended/Future/IFutureTestQueryable.cs b/Source/EntityFramework.Extended/Future/IFutureTestQueryable.cs new file mode 100644 index 0000000..889b30b --- /dev/null +++ b/Source/EntityFramework.Extended/Future/IFutureTestQueryable.cs @@ -0,0 +1,15 @@ +using System.Linq; + +namespace EntityFramework.Future +{ + /// + /// Allows mocking and testing of the Future() ExtensionMethods. + /// + public interface IFutureTestQueryable : IQueryable { } + + /// + /// Allows mocking and testing of the Future() ExtensionMethods. + /// + /// Return type + public interface IFutureTestQueryable : IQueryable, IFutureTestQueryable { } +}