public void CorrectValueFor_ConstantExpr_RefType() { var eval = new Evaluator(); Expression<Func<bool>> expr = () => "test" == str; Expression leftExpr = (expr.Body as BinaryExpression).Left; object leftVal = eval.GetConstantVal(leftExpr); Assert.AreEqual(leftVal, "test"); }
public void CorrectTestResultFor_StaticMethod() { var eval = new Evaluator(); bool result1 = eval.GetTestResult(() => Sample.GetStaticFalse()); bool result2 = eval.GetTestResult(() => Sample.GetStaticTrue(2, "test")); Assert.IsFalse(result1); Assert.IsTrue(result2); }
public void CorrectTestResultFor_Binary() { var eval = new Evaluator(); bool result1 = eval.GetTestResult(() => one == 2); bool result2 = eval.GetTestResult(() => one != 2); Assert.IsFalse(result1); Assert.IsTrue(result2); }
public void CorrectTestResultFor_InstanceMethod() { var eval = new Evaluator(); var tester = new Sample(); bool result1 = eval.GetTestResult(() => tester.GetFalse()); bool result2 = eval.GetTestResult(() => tester.GetTrue(2, "test")); Assert.IsFalse(result1); Assert.IsTrue(result2); }
public void CorrectTestResultFor_UnaryNot() { var eval = new Evaluator(); bool result1 = eval.GetTestResult(() => !(one == 1)); bool result2 = eval.GetTestResult(() => !(_false)); bool result3 = eval.GetTestResult(() => !(Sample.GetStaticFalse())); Assert.IsFalse(result1); Assert.IsTrue(result2); Assert.IsTrue(result3); }
public static void True(Expression<Func<bool>> expr, string message = "") { var eval = new Evaluator(); if (eval.GetTestResult(expr)) return; string testedCode = GetTestString(expr); throw new ExpertException (message) { TestedCode = testedCode, TestedData = eval.GetTestedValues(expr), }; }
public void CorrectValuesFor_Unary_On_StaticCall() { var eval = new Evaluator(); var tester = new Sample(); Expression<Func<bool>> expr = () => !(Sample.GetStaticFalse()); object[] values = eval.GetUnaryValues(expr.Body); Assert.AreEqual(values.Length, 1); Assert.AreEqual(values[0], false); }
public void CorrectValuesFor_Unary_On_Variable() { var eval = new Evaluator(); Expression<Func<bool>> expr = () => !(_false); object[] values = eval.GetUnaryValues(expr.Body); Assert.AreEqual(values.Length, 1); Assert.AreEqual(values[0], false); }
public void CorrectValuesFor_Binary() { var eval = new Evaluator(); Expression<Func<bool>> expr = () => one == 2; Tuple<object, object> values = eval.GetBinaryValues(expr.Body); Assert.AreEqual(values.Item1, 1); Assert.AreEqual(values.Item2, 2); }
public void CorrectValuesFor_Unary_On_Binary() { var eval = new Evaluator(); Expression<Func<bool>> expr = () => !(one == 2); object[] values = eval.GetUnaryValues(expr.Body); Assert.AreEqual(values.Length, 2); Assert.AreEqual(values[0], 1); Assert.AreEqual(values[1], 2); }
public void CorrectValueFor_VariableExpr_ValueType() { var eval = new Evaluator(); Expression<Func<bool>> expr = () => 1 == two; Expression rightExpr = (expr.Body as BinaryExpression).Right; object rightVal = eval.GetMemberVal(rightExpr); Assert.AreEqual(rightVal, 2); }
public void CorrectValueFor_StaticCallExpr_ValueType() { var eval = new Evaluator(); Expression<Func<bool>> expr = () => Sample.GetStaticTrue(); Expression call = (expr.Body as MethodCallExpression); object val = eval.GetMemberVal(call); Assert.AreEqual(val, true); }
public void CorrectValueFor_StaticCallExpr_RefType() { var eval = new Evaluator(); Expression<Func<string>> expr = () => Sample.GetStaticString(); Expression call = (expr.Body as MethodCallExpression); object val = eval.GetMemberVal(call); Assert.AreEqual(val, "str"); }
public void CorrectValueFor_MemberVariableExpr_Instance() { var tester = new Sample(); var eval = new Evaluator(); Expression<Func<bool>> expr = () => one == tester.Two; Expression rightExpr = (expr.Body as BinaryExpression).Right; object rightVal = eval.GetMemberVal(rightExpr); Assert.AreEqual(rightVal, 2); }
public void CorrectValueFor_InstanceCallExpr_ValueType() { var eval = new Evaluator(); var tester = new Sample(); Expression<Func<bool>> expr = () => tester.GetTrue(); Expression call = (expr.Body as MethodCallExpression); object val = eval.GetMemberVal(call); Assert.AreEqual(val, true); }