public void NewArrayInit() { NotSupportedException expectedException = new NotSupportedException( string.Format(ErrorStrings.UnsupportedExpressionType, ExpressionType.NewArrayInit)); Activity we = ExpressionTestRuntime.Convert((env) => new int[] { 1, 2, 3 }, expectedException); }
public void ConvertNull() { ArgumentNullException expectedException = new ArgumentNullException("expression", ErrorStrings.ExpressionRequiredForConversion); Expression <Func <ActivityContext, int> > expression = null; ExpressionTestRuntime.Convert(expression, expectedException); }
public void NewWithInitializer() { NotSupportedException expectedException = new NotSupportedException( string.Format(ErrorStrings.UnsupportedExpressionType, ExpressionType.MemberInit)); ExpressionTestRuntime.Convert((env) => new DummyHelper() { StringVar = null }, expectedException); }
// Unsupported binary operator public void UnsupportedBinaryOperator() { NodeExpressionPair node = ExpressionLeafs.UnsupportedBinaryOperator; Expression <Func <ActivityContext, int> > lambdaExpression = Expression.Lambda <Func <ActivityContext, int> >((Expression)node.LeafExpression, Expression.Parameter(typeof(ActivityContext), "context")); NotSupportedException expectedException = new NotSupportedException( string.Format(ErrorStrings.UnsupportedExpressionType, ExpressionType.Coalesce)); ExpressionTestRuntime.Convert(lambdaExpression, expectedException); }
// Unsupported unary operator public void UnsupportedUnaryOperator() { NotSupportedException expectedException = new NotSupportedException( string.Format(ErrorStrings.UnsupportedExpressionType, ExpressionType.NegateChecked)); Expression <Func <ActivityContext, int> > expression = Expression.Lambda <Func <ActivityContext, int> >( Expression.MakeUnary(ExpressionType.NegateChecked, Expression.Constant(100), typeof(int)), Expression.Parameter(typeof(ActivityContext), "context")); ExpressionTestRuntime.Convert(expression, expectedException); }
public static Activity ConvertAndValidate <TResult>(Expression <Func <ActivityContext, TResult> > expr, Activity expectedActivity, Exception expectedException) { bool expectSuccess = expectedException == null ? true : false; Activity act = ExpressionTestRuntime.Convert(expr, expectedException); if (expectSuccess) { ExpressionTestRuntime.ValidateActivity(expectedActivity, act); } act = ExpressionTestRuntime.TryConvert(expr, expectSuccess); if (expectSuccess) { ExpressionTestRuntime.ValidateActivity(expectedActivity, act); } return(act); }
// Method call with VarArg public void MethodCallWithVarArg() { TargetInvocationException expectedException = new TargetInvocationException(null); ExpressionTestRuntime.Convert((env) => DummyHelper.MethodCallWithVarArg(1, 2, 3), expectedException); }