@@ -1402,15 +1402,29 @@ public static IEnumerable<TestCaseData> TestCasesForExceptionThrowingEvaluation
14021402
14031403 #region On the fly pre events cancel
14041404
1405- evaluator = new ExpressionEvaluator ( ) ;
1405+ evaluator = new ExpressionEvaluator ( new Dictionary < string , object >
1406+ {
1407+ { "P1var" , "P1" } ,
1408+ { "myObj" , new ClassForTest1 ( ) } ,
1409+ } ) ;
14061410
14071411 evaluator . PreEvaluateVariable += ( sender , e ) =>
14081412 {
14091413 if ( e . Name . StartsWith ( "P" ) )
14101414 e . CancelEvaluation = true ;
14111415 } ;
14121416
1417+ evaluator . PreEvaluateFunction += ( sender , e ) =>
1418+ {
1419+ if ( e . Name . StartsWith ( "A" ) )
1420+ e . CancelEvaluation = true ;
1421+ } ;
1422+
14131423 yield return new TestCaseData ( evaluator , "Pi" , typeof ( ExpressionEvaluatorSyntaxErrorException ) ) . SetCategory ( "OnTheFly canceled Var" ) ;
1424+ yield return new TestCaseData ( evaluator , "P1var" , typeof ( ExpressionEvaluatorSyntaxErrorException ) ) . SetCategory ( "OnTheFly canceled Var" ) ;
1425+ yield return new TestCaseData ( evaluator , "myObj.PropertyThatWillFailed" , typeof ( ExpressionEvaluatorSyntaxErrorException ) ) . SetCategory ( "OnTheFly canceled Var" ) ;
1426+ yield return new TestCaseData ( evaluator , "myObj.Add3To(5)" , typeof ( ExpressionEvaluatorSyntaxErrorException ) ) . SetCategory ( "OnTheFly canceled Func" ) ;
1427+ yield return new TestCaseData ( evaluator , "Abs(-5)" , typeof ( ExpressionEvaluatorSyntaxErrorException ) ) . SetCategory ( "OnTheFly canceled Func" ) ;
14141428
14151429 #endregion
14161430 }
@@ -1565,14 +1579,20 @@ public static IEnumerable<TestCaseData> TestCasesEvaluateWithSpecificEvaluator
15651579
15661580 #region Onthefly events (Pre events and/or Generics and/or Static)
15671581
1568- ExpressionEvaluator evaluatorOnTheFlies = new ExpressionEvaluator ( ) ;
1582+ ExpressionEvaluator evaluatorOnTheFlyGenericTypes = new ExpressionEvaluator ( new Dictionary < string , object >
1583+ {
1584+ { "myvar1" , 10 } ,
1585+ { "myvar2" , 3 } ,
1586+ } ) ;
15691587
15701588 evaluatorOnTheFlies . Namespaces . Add ( "CodingSeb.ExpressionEvaluator.Tests" ) ;
15711589
15721590 void VariableEval ( object sender , VariableEvaluationEventArg e )
15731591 {
1574- if ( e . Name . Equals ( "GetSpecifiedGenericTypesVar" ) )
1592+ if ( e . Name . Equals ( "GetSpecifiedGenericTypesVar" ) )
15751593 e . Value = e . EvaluateGenericTypes ( ) ;
1594+ else if ( e . Name . Equals ( "myvar2" ) )
1595+ e . Value = 50 ;
15761596 else if ( e . This is ClassOrTypeName classOrTypeName && classOrTypeName . Type == typeof ( ClassForTest1 ) && e . Name . Equals ( "OnTheFlyStaticVar" ) )
15771597 {
15781598 e . Value = 10 ;
@@ -1665,6 +1685,16 @@ void Evaluator_PreEvaluateVariable(object sender, VariablePreEvaluationEventArg
16651685 . SetCategory ( "On the fly var" )
16661686 . SetCategory ( "Static Onthefly" ) ;
16671687
1688+ yield return new TestCaseData ( evaluatorOnTheFlyGenericTypes
1689+ , "myvar1" )
1690+ . Returns ( 5 )
1691+ . SetCategory ( "var evaluation priority" ) ;
1692+
1693+ yield return new TestCaseData ( evaluatorOnTheFlyGenericTypes
1694+ , "myvar2" )
1695+ . Returns ( 3 )
1696+ . SetCategory ( "var evaluation priority" ) ;
1697+
16681698 yield return new TestCaseData ( evaluatorOnTheFlies
16691699 , "ClassForTest1.OnTheFlyStaticPreFunc()" )
16701700 . Returns ( 5 )
@@ -1678,6 +1708,15 @@ void Evaluator_PreEvaluateVariable(object sender, VariablePreEvaluationEventArg
16781708 . SetCategory ( "Static Onthefly" ) ;
16791709
16801710 #endregion
1711+
1712+ #region bug resolution
1713+
1714+ yield return new TestCaseData ( new ExpressionEvaluator ( )
1715+ , "(new List<Regex>()).GetType()" )
1716+ . Returns ( typeof ( List < Regex > ) )
1717+ . SetCategory ( "Bug resolution" ) ;
1718+
1719+ #endregion
16811720 }
16821721 }
16831722
0 commit comments