public void TryEvaluateFunction_InvalidExpression_ErrorPopulatedAndReturned()
        {
            const string expression = @"Sum(10, 10,asdasd)";

            _eval = MathOpsFactory.CreateFunctionEvaluator();
            var hasSuceeded = _eval.TryEvaluateFunction(expression, out string result, out string error);

            if (!hasSuceeded)
            {
                Assert.IsTrue(error.Length > 0);
            }
            else
            {
                Assert.Fail("The Function Evaluator did not correctly error on an invalid expression");
            }
        }
        public void TryEvaluateFunction_LiteralsPassedToFunction_EvaluationReturnsCorrectly()
        {
            const string expression = @"Sum(10, 10)";

            _eval = MathOpsFactory.CreateFunctionEvaluator();
            var hasSuceeded = _eval.TryEvaluateFunction(expression, out string result, out string error);

            if (hasSuceeded)
            {
                Assert.AreEqual(result, "20");
            }
            else
            {
                Assert.Fail("The Evaluation Manager was unable to resolve evaluation, this is a huge problem");
            }
        }
        /// <summary>
        /// The execute method that is called when the activity is executed at run time and will hold all the logic of the activity
        /// </summary>
        protected override void OnExecute(NativeActivityContext context)
        {
            _debugInputs  = new List <DebugItem>();
            _debugOutputs = new List <DebugItem>();
            IDSFDataObject    dataObject = context.GetExtension <IDSFDataObject>();
            IDataListCompiler compiler   = DataListFactory.CreateDataListCompiler();

            ErrorResultTO allErrors   = new ErrorResultTO();
            ErrorResultTO errors      = new ErrorResultTO();
            Guid          executionId = DataListExecutionID.Get(context);

            allErrors.MergeErrors(errors);
            InitializeDebug(dataObject);
            // Process if no errors
            try
            {
                IsSingleValueRule.ApplyIsSingleValueRule(Result, allErrors);

                if (dataObject.IsDebugMode())
                {
                    AddDebugInputItem(executionId);
                }
                IFunctionEvaluator functionEvaluator = MathOpsFactory.CreateFunctionEvaluator();

                string input = string.IsNullOrEmpty(Expression) ? Expression : Expression.Replace("\\r", string.Empty).Replace("\\n", string.Empty).Replace(Environment.NewLine, "");

                IEvaluationFunction evaluationFunctionTo = MathOpsFactory.CreateEvaluationExpressionTO(input);

                string result = functionEvaluator.EvaluateFunction(evaluationFunctionTo, executionId, out errors);
                allErrors.MergeErrors(errors);

                compiler.Upsert(executionId, Result, result, out errors);

                if (dataObject.IsDebugMode() && !allErrors.HasErrors())
                {
                    AddDebugOutputItem(Result, executionId);
                }
                allErrors.MergeErrors(errors);
            }
            catch (Exception ex)
            {
                Dev2Logger.Log.Error("Calculate Exception", ex);
                allErrors.AddError(ex.Message);
            }
            finally
            {
                // Handle Errors
                var hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfCalculateActivity", allErrors);
                    compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors);
                    compiler.Upsert(executionId, Result, (string)null, out errors);
                }
                if (dataObject.IsDebugMode())
                {
                    if (hasErrors)
                    {
                        AddDebugOutputItem(Result, executionId);
                    }
                    DispatchDebugState(context, StateType.Before);
                    DispatchDebugState(context, StateType.After);
                }
            }
        }