public void CanTranslateFetchClause() { var session = new Mock <ISession>(); var executor = new SpecificationExecutor(); var specification = new WithFetch(); var queryable = executor.ExecuteSpecification(session.Object, specification); var fetchMethodInfo = ReflectionHelper.FindMethod( BindingFlags.Static | BindingFlags.Public, typeof(EagerFetchingExtensionMethods), nameof(EagerFetchingExtensionMethods.Fetch), null, new ArgumentConstraint(typeof(IQueryable <>), 1), new ArgumentConstraint(typeof(Expression <>).MakeGenericType(typeof(Func <,>)), 2)); var lambda = (MethodCallExpression)queryable.Expression; Assert.Equal(ExpressionType.Call, lambda.NodeType); Assert.Same( fetchMethodInfo.MakeGenericMethod(typeof(User), typeof(Person)), lambda.Method); Assert.Same( specification.Expression, ((UnaryExpression)lambda.Arguments.ElementAt(1)).Operand); }
public void CanTranslateFetchClause() { var context = new Mock <Context>(); context .Setup(x => x.Set <User>()) .Returns(new FakeSet <User>()); var executor = new SpecificationExecutor(); var specification = new WithFetch(); var queryable = executor.ExecuteSpecification(context.Object, specification); var fetchMethodInfo = ReflectionHelper.FindMethod( BindingFlags.Static | BindingFlags.Public, typeof(EntityFrameworkQueryableExtensions), nameof(EntityFrameworkQueryableExtensions.Include), null, new ArgumentConstraint(typeof(IQueryable <>), 1), new ArgumentConstraint(typeof(Expression <>).MakeGenericType(typeof(Func <,>)), 2)); var lambda = (MethodCallExpression)queryable.Expression; Assert.Equal(ExpressionType.Call, lambda.NodeType); Assert.Same( fetchMethodInfo.MakeGenericMethod(typeof(User), typeof(Person)), lambda.Method); Assert.Same( specification.Expression, ((UnaryExpression)lambda.Arguments.ElementAt(1)).Operand); }