public void Identifies_binary_operation_as_invalid_expression()
        {
            var dao = new DataAccessOnlyAnalyser();
            var enp = new ExpressionNodePath();

            Expression <Func <DateTime, long> > testLambda = ((DateTime a) => a.Ticks + 9);

            dao.Initialise(testLambda.Parameters[0]);
            enp.Add(new ClassifiedExpression(testLambda.Body));

            Assert.IsFalse(dao.ShouldProviderHandleExpression(enp));
        }
        public void Identifies_data_based_array_index_as_valid_expression()
        {
            var dao = new DataAccessOnlyAnalyser();
            var enp = new ExpressionNodePath();

            Expression <Func <string[], string> > testLambda = ((string[] a) => a[a.GetHashCode()]);

            dao.Initialise(testLambda.Parameters[0]);
            enp.Add(new ClassifiedExpression(testLambda.Body));

            Assert.IsTrue(dao.ShouldProviderHandleExpression(enp));
        }
        public void Identifies_constant_as_invalid_expression()
        {
            var dao = new DataAccessOnlyAnalyser();
            var enp = new ExpressionNodePath();

            Expression <Func <string, int> > testLambda = ((string a) => 1);

            dao.Initialise(testLambda.Parameters[0]);
            enp.Add(new ClassifiedExpression(testLambda.Body));

            Assert.IsFalse(dao.ShouldProviderHandleExpression(enp));
        }
        public void Identifies_field_access_as_valid_expression()
        {
            var dao = new DataAccessOnlyAnalyser();
            var enp = new ExpressionNodePath();

            Expression <Func <ClassWithField, long> > testLambda = ((ClassWithField a) => a.Test);

            dao.Initialise(testLambda.Parameters[0]);
            enp.Add(new ClassifiedExpression(testLambda.Body));

            Assert.IsTrue(dao.ShouldProviderHandleExpression(enp));
        }
        public void Identifies_extension_method_call_as_invalid_expression()
        {
            var dao = new DataAccessOnlyAnalyser();
            var enp = new ExpressionNodePath();

            Expression <Func <string, IEnumerable <char> > > testLambda = ((string a) => a.Reverse());

            dao.Initialise(testLambda.Parameters[0]);
            enp.Add(new ClassifiedExpression(testLambda.Body));

            Assert.IsFalse(dao.ShouldProviderHandleExpression(enp));
        }
        public void Identifies_member_access_and_indexer_as_valid_expression()
        {
            var dao = new DataAccessOnlyAnalyser();
            var enp = new ExpressionNodePath();

            Expression <Func <string, char> > testLambda = ((string a) => a.ToString()[0]);

            dao.Initialise(testLambda.Parameters[0]);
            enp.Add(new ClassifiedExpression(testLambda.Body));

            Assert.IsTrue(dao.ShouldProviderHandleExpression(enp));
        }
        public void Identifies_non_data_based_array_as_invalid_expression()
        {
            var dao = new DataAccessOnlyAnalyser();
            var enp = new ExpressionNodePath();

            Expression <Func <string, char> > testLambda = ((string a) => DateTime.Now.ToString()[a.GetHashCode()]);

            dao.Initialise(testLambda.Parameters[0]);
            enp.Add(new ClassifiedExpression(testLambda.Body));

            Assert.IsFalse(dao.ShouldProviderHandleExpression(enp));
        }
Example #8
0
        public void Two_node_path_parents_are_correct()
        {
            var path     = new ExpressionNodePath();
            var rootExp  = new ClassifiedExpression(null);
            var childExp = new ClassifiedExpression(null);

            path.Insert(0, rootExp);
            Assert.AreEqual(null, path.Parent);

            path.Insert(0, childExp);
            Assert.AreEqual(rootExp, path.Parent);
        }
        private bool ShouldProviderHandleExpression(ExpressionNodePath nodePath)
        {
            // first, check if we want to filter this out from the analyser

            // case for exclusion: expression is a parameter to a lambda
            if (nodePath.Count > 1 && nodePath[1].Expression is LambdaExpression &&
                ((LambdaExpression)nodePath[1].Expression).Parameters.Contains(nodePath[0].Expression))
            {
                return(false);
            }

            // finally, check with analyser
            return(this._analyser.ShouldProviderHandleExpression(nodePath));
        }
        /// <summary>
        /// Returns true if the supplied expression should be passed to the underlying provider
        /// in its entirety.  If the expression is not a leaf node (if there are children), the
        /// caller can call again on child nodes to determine if part of the expression is
        /// suitable instead.
        /// </summary>
        /// <param name="node">The path through the expression tree, ending with the node in question</param>
        /// <returns>'true' if the underlying provider should be handed this expression to retrieve</returns>
        public bool ShouldProviderHandleExpression(ExpressionNodePath node)
        {
            var isDataAccessExpr = IsDataAccessExpression(node.Current.Expression);

            return(isDataAccessExpr);
        }
 /// <summary>
 /// Returns true if the supplied expression should be passed to the underlying provider
 /// in its entirety.  If the expression is not a leaf node (if there are children), the
 /// caller can call again on child nodes to determine if part of the expression is
 /// suitable instead.
 /// Currently unimplemented for EfSupportedAutoAnalyser.
 /// </summary>
 /// <param name="node">The path through the expression tree, ending with the node in question</param>
 /// <returns>'true' if the underlying provider should be handed this expression to retrieve</returns>
 public bool ShouldProviderHandleExpression(ExpressionNodePath node)
 {
     throw new NotImplementedException();
 }
 private DeferExpressionTransformer(IExpressionAnalyser analyser)
 {
     _analyser        = analyser;
     _transformation  = new DeferTransformation();
     _currentNodePath = new ExpressionNodePath();
 }
Example #13
0
        public void Empty_node_path_yields_null_current()
        {
            var path = new ExpressionNodePath();

            Assert.IsNull(path.Current);
        }