From 95469368361088e819cd87ccffdd45f09653a51c Mon Sep 17 00:00:00 2001 From: Russell West Date: Wed, 24 Feb 2016 23:03:34 -0800 Subject: [PATCH 1/2] FutureExtensions Work * Cleaning up extra error checking. * Fixing spelling of 'Underlying' --- .../EntityFramework.Extended/Extensions/FutureExtensions.cs | 4 ---- Source/EntityFramework.Extended/Future/FutureValue.cs | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Source/EntityFramework.Extended/Extensions/FutureExtensions.cs b/Source/EntityFramework.Extended/Extensions/FutureExtensions.cs index 8b18a97..da3f850 100644 --- a/Source/EntityFramework.Extended/Extensions/FutureExtensions.cs +++ b/Source/EntityFramework.Extended/Extensions/FutureExtensions.cs @@ -65,8 +65,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); @@ -137,8 +135,6 @@ public static FutureValue FutureFirstOrDefault(this IQueryable 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; From 53cd7f6d67a91e821c3fefbeb0f9c5770c5f3ac6 Mon Sep 17 00:00:00 2001 From: Russell West Date: Wed, 24 Feb 2016 23:29:54 -0800 Subject: [PATCH 2/2] FutureExtensonMethods Work * Adding 'test' Queryable interfaces: IFutureTestQueryable and * IFutureTestQueryable * Adding a test hook to extension methods to return wrapped queryable when * given an IQueryable that also inherits from one of the test interfaces. These changes allow mocking and testing of code which uses the FutureExtensionMethods. --- .../Extensions/FutureExtensions.cs | 24 +++++++++++++++++++ .../Future/IFutureTestQueryable.cs | 15 ++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 Source/EntityFramework.Extended/Future/IFutureTestQueryable.cs diff --git a/Source/EntityFramework.Extended/Extensions/FutureExtensions.cs b/Source/EntityFramework.Extended/Extensions/FutureExtensions.cs index da3f850..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( @@ -88,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) @@ -129,7 +147,13 @@ 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); 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 { } +}