示例#1
0
        public CalculateIntellisenseProvider(ISyntaxTreeBuilderHelper syntaxTreeBuilderHelper)
        {
            _syntaxTreeBuilderHelper = syntaxTreeBuilderHelper;
            IntellisenseProviderType = IntellisenseProviderType.NonDefault;
            IFrameworkRepository <IFunction> functionList = MathOpsFactory.FunctionRepository();

            functionList.Load();
            bool creatingFunctions = false;

            if (_functionNames == null)
            {
                creatingFunctions = true;
                _functionNames    = new HashSet <string>(StringComparer.Ordinal);
            }

            IntellisenseResult = functionList.All().Select(currentFunction =>
            {
                string description         = currentFunction.Description;
                string dropDownDescription = description;
                if (description != null && description.Length > 80)
                {
                    dropDownDescription = description.Substring(0, 77) + "...";
                }
                if (creatingFunctions)
                {
                    _functionNames.Add(currentFunction.FunctionName);
                }
                IntellisenseProviderResult result = new IntellisenseProviderResult(this, currentFunction.FunctionName, dropDownDescription, description, currentFunction.arguments != null ? currentFunction.arguments.ToArray() : new string[0], currentFunction.ArgumentDescriptions != null ? currentFunction.ArgumentDescriptions.ToArray() : new string[0]);
                return(result);
            }).OrderBy(p => p.Name).ToList();
        }
        public void FunctionRepository_SaveCollection_ValidFunction_Expected_RepoUpdatedWithNewFunction()
        {
            IFrameworkRepository <IFunction> functionRepo = MathOpsFactory.FunctionRepository();
            string        functionName = "TestFunction";
            List <string> arguments    = new List <string>()
            {
                "args"
            };
            List <string> argumentDescriptions = new List <string>()
            {
                "the first argument"
            };
            string description = "Test Description";

            string function2Name = "TestFunction2";

            // The function repository must be loaded in order to populate the function list
            functionRepo.Load();


            IFunction myfirstFunction            = MathOpsFactory.CreateFunction(functionName, arguments, argumentDescriptions, description);
            IFunction mySecondFunction           = MathOpsFactory.CreateFunction(function2Name, arguments, argumentDescriptions, description);
            ICollection <IFunction> functionList = new List <IFunction>()
            {
                myfirstFunction, mySecondFunction
            };

            functionRepo.Save(functionList);

            Assert.AreEqual(2, functionRepo.Find(c => c.FunctionName.Contains(functionName)).Count);
        }
        public void CreateCustomFunction_NullXamCalculationManager_Expected_ExceptionReturned()
        {
            string        functionName = "TestFunction";
            List <string> arguments    = new List <string> {
                "x", "y"
            };
            List <string> argumentDescriptions = new List <string> {
                "the first argument", "the second argument"
            };
            string description = "My TestFunction";

            IFunction func = MathOpsFactory.CreateFunction(functionName, arguments, argumentDescriptions, description);
            IDev2CalculationManager manager  = null;
            Func <double[], double> function = AddAbs;

            try
            {
                func.CreateCustomFunction(functionName, arguments, argumentDescriptions, description, function, manager);
            }
            catch (NullReferenceException)
            {
                // since this exception is thrown we have our answer.
                Assert.IsTrue(true);
            }
        }
        public void FunctionRepository_Remove_ValidFunction_Expected_FunctionRemovedFromRepo()
        {
            IFrameworkRepository <IFunction> functionRepo = MathOpsFactory.FunctionRepository();
            string        functionName = "TestFunction";
            List <string> arguments    = new List <string>()
            {
                "args"
            };
            List <string> argumentDescriptions = new List <string>()
            {
                "the first argument"
            };
            string description = "Test Description";

            // The function repository must be loaded in order to populate the function list
            functionRepo.Load();


            IFunction myFunction = MathOpsFactory.CreateFunction(functionName, arguments, argumentDescriptions, description);

            // save the new function
            functionRepo.Save(myFunction);

            functionRepo.Remove(myFunction);

            Assert.AreEqual(0, functionRepo.Find(c => c.FunctionName.Equals(functionName)).Count);
        }
        public void CreateEvaluationFunctionTO_ShouldHaveConstructor()
        {
            var evaluationFunctionTo = MathOpsFactory.CreateEvaluationFunctionTO("someFunction");

            Assert.IsNotNull(evaluationFunctionTo);
            Assert.AreEqual("someFunction", evaluationFunctionTo.Function);
        }
        public void FunctionRepository_Find_NullExpression_Expected_ErrorFromRepository()
        {
            IFrameworkRepository <IFunction> functionRepo = MathOpsFactory.FunctionRepository();

            // The function repository must be loaded in order to populate the function list
            functionRepo.Load();
            ICollection <IFunction> functions = functionRepo.Find(null);
        }
示例#7
0
        public void Function_NullDescriptionAndArguments_Expected_FunctionStillCreated()
        {
            const string functionName = "Test Function";

            IFunction func = MathOpsFactory.CreateFunction(functionName, null, null, null);

            Assert.IsNotNull(func);
        }
        public void FunctionRepository_Find_NullExpression_Expected_ErrorFromRepository()
        {
            var functionRepo = MathOpsFactory.FunctionRepository();

            // The function repository must be loaded in order to populate the function list
            functionRepo.Load();
            functionRepo.Find(null);
        }
示例#9
0
        public void Function_NullListOfArguments_Expected_EmptyListofArguments()
        {
            const string functionName = "Test Function";
            const string description  = "Some Test Function";

            IFunction func = MathOpsFactory.CreateFunction(functionName, null, null, description);

            Assert.AreEqual(0, func.arguments.Count);
        }
        public void FunctionRepository_Remove_NullFunction_Expected_ArgumentNullException()
        {
            var functionRepo = MathOpsFactory.FunctionRepository();

            // The function repository must be loaded in order to populate the function list
            functionRepo.Load();

            functionRepo.Remove((IFunction)null);
        }
        public void FunctionRepository_Load_DefaultRepository()
        {
            var functionRepo = MathOpsFactory.FunctionRepository();

            functionRepo.Load();
            functionRepo.All();

            Assert.IsTrue(functionRepo.All().Count > 0);
        }
        public void FunctionRepository_Load_DefaultRepository()
        {
            IFrameworkRepository <IFunction> functionRepo = MathOpsFactory.FunctionRepository();

            functionRepo.Load();
            IEnumerable <IFunction> functions = functionRepo.All();

            Assert.IsTrue(functionRepo.All().Count > 0);
        }
        public void FunctionRepository_FindSingle_NullExpression_Expected_NullReturned()
        {
            var functionRepo = MathOpsFactory.FunctionRepository();

            // The function repository must be loaded in order to populate the function list
            functionRepo.Load();
            var functions = functionRepo.FindSingle(null);

            Assert.IsNull(functions);
        }
        public void FunctionRepository_FindSingle_ExpressionYieldsNoResult_Expected_EmptyFunctionReturned()
        {
            IFrameworkRepository <IFunction> functionRepo = MathOpsFactory.FunctionRepository();

            // The function repository must be loaded in order to populate the function list
            functionRepo.Load();
            IFunction function = functionRepo.FindSingle(c => c.FunctionName == string.Empty);

            Assert.IsInstanceOfType(function, typeof(IFunction));
        }
        public void FunctionRepository_RemoveCollection_NullCollection_Expected_ArgumentException()
        {
            var functionRepo = MathOpsFactory.FunctionRepository();

            // The function repository must be loaded in order to populate the function list
            functionRepo.Load();
            var beforeEmptySave = functionRepo.Find(c => c.FunctionName != string.Empty).Count;

            functionRepo.Remove((ICollection <IFunction>)null);
            Assert.IsNotNull(beforeEmptySave);
        }
        public void FunctionRepository_Find_ExpressionYieldsNoResult_Expected_EmptyCollectionReturned()
        {
            IFrameworkRepository <IFunction> functionRepo = MathOpsFactory.FunctionRepository();

            // The function repository must be loaded in order to populate the function list
            functionRepo.Load();

            ICollection <IFunction> functions = functionRepo.Find(c => c.FunctionName == string.Empty);

            Assert.AreEqual(0, functions.Count);
        }
示例#17
0
        public void Function_NullDescriptionAndArguments_Expected_FunctionStillCreated()
        {
            string        functionName         = "Test Function";
            List <string> arguments            = null;
            List <string> argumentDescriptions = null;
            string        description          = null;

            IFunction func = MathOpsFactory.CreateFunction(functionName, arguments, argumentDescriptions, description);

            Assert.IsNotNull(func);
        }
示例#18
0
        public void Function_AllInputsValid_Expected_ValidFunctionCreated()
        {
            const string  functionName         = "Test Function";
            List <string> arguments            = new List <string>();
            List <string> argumentDescriptions = new List <string>();
            const string  description          = "Some Test Function";

            IFunction func = MathOpsFactory.CreateFunction(functionName, arguments, argumentDescriptions, description);

            Assert.IsNotNull(func);
        }
        public void FunctionRepository_FindSingle_ValidExpression_Expected_SingleResultReturned()
        {
            IFrameworkRepository <IFunction> functionRepo = MathOpsFactory.FunctionRepository();

            // The function repository must be loaded in order to populate the function list
            functionRepo.Load();

            IFunction function = functionRepo.FindSingle(c => c.FunctionName.Contains("s"));

            Assert.IsNotNull(function);
        }
        public void FunctionRepository_Find_ValidExpressionAndReturnsData_Expected_ListReturned()
        {
            IFrameworkRepository <IFunction> functionRepo = MathOpsFactory.FunctionRepository();

            // The function repository must be loaded in order to populate the function list
            functionRepo.Load();

            ICollection <IFunction> functions = functionRepo.Find(c => c.FunctionName.Length > 0);


            Assert.IsTrue(functions.Count > 0);
        }
        public void FunctionRepository_RemoveCollection_NullCollection_Expected_ArgumentException()
        {
            IFrameworkRepository <IFunction> functionRepo = MathOpsFactory.FunctionRepository();

            // The function repository must be loaded in order to populate the function list
            functionRepo.Load();
            int beforeEmptySave = functionRepo.Find(c => c.FunctionName != string.Empty).Count;

            ICollection <IFunction> functionList = null;

            functionRepo.Remove(functionList);
        }
        public void FunctionRepository_Remove_NullFunction_Expected_ArgumentNullException()
        {
            IFrameworkRepository <IFunction> functionRepo = MathOpsFactory.FunctionRepository();

            // The function repository must be loaded in order to populate the function list
            functionRepo.Load();


            IFunction myFunction = null;

            functionRepo.Remove(myFunction);
        }
示例#23
0
        public void Function_NullDescription_Expected_EmptyDescription()
        {
            const string  functionName = "Test Function";
            List <string> arguments    = new List <string> {
                "arg1"
            };
            List <string> argumentDescriptions = new List <string> {
                "the first argument"
            };

            IFunction func = MathOpsFactory.CreateFunction(functionName, arguments, argumentDescriptions, null);

            Assert.IsTrue(func.Description.Equals(string.Empty));
        }
示例#24
0
        public void CreateCustomFunction_NullArgumentDescription_Expected_ExceptionReturned()
        {
            const string  functionName = "TestFunction";
            List <string> arguments    = new List <string> {
                "x", "y"
            };
            const string description = "My TestFunction";

            IFunction func = MathOpsFactory.CreateFunction(functionName, arguments, null, description);
            IDev2CalculationManager manager = new Dev2CalculationManager();

            func.CreateCustomFunction(functionName, arguments, null, description, null, manager);

            Assert.AreNotEqual(null, func.ArgumentDescriptions);
        }
示例#25
0
        public void Function_NullFunctionName_Expected_ExceptionReturned()
        {
            List <string> arguments            = new List <string>();
            List <string> argumentDescriptions = new List <string>();
            const string  description          = "Some Test Function";

            try
            {
                MathOpsFactory.CreateFunction(null, arguments, argumentDescriptions, description);
            }
            catch (ArgumentNullException)
            {
                // If we get this exception, it is expected.
                Assert.IsTrue(true);
            }
        }
示例#26
0
        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");
            }
        }
示例#27
0
        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 FunctionRepository_RemopveCollection_EmptyCollection_Expected_NoFunctionsRemovedFromRepo()
        {
            IFrameworkRepository <IFunction> functionRepo = MathOpsFactory.FunctionRepository();

            // The function repository must be loaded in order to populate the function list
            functionRepo.Load();
            int beforeEmptySave = functionRepo.Find(c => c.FunctionName != string.Empty).Count;

            ICollection <IFunction> functionList = new List <IFunction>();

            functionRepo.Remove(functionList);

            int afterEmptySave = functionRepo.Find(c => c.FunctionName != string.Empty).Count;

            Assert.AreEqual(beforeEmptySave, afterEmptySave);
        }
        public void FunctionRepository_RemoveCollection_ValidFunction_Expected_RepoUpdatedWithNewFunction()
        {
            IFrameworkRepository <IFunction> functionRepo = MathOpsFactory.FunctionRepository();


            // The function repository must be loaded in order to populate the function list
            functionRepo.Load();
            ICollection <IFunction> functionsToRemove = functionRepo.Find(c => c.FunctionName.Contains("s"));
            int functionCountBeforeRemove             = functionRepo.Find(c => c.FunctionName != string.Empty).Count;

            functionRepo.Remove(functionsToRemove);

            int functionCountAfterRemove = functionRepo.Find(c => c.FunctionName != string.Empty).Count;

            Assert.IsTrue(functionCountAfterRemove < functionCountBeforeRemove);
        }
        public void FunctionRepository_SaveCollection_EmptyCollection_Expected_RepoFunctionCountRemainsTheSame()
        {
            var functionRepo = MathOpsFactory.FunctionRepository();

            // The function repository must be loaded in order to populate the function list
            functionRepo.Load();
            var beforeEmptySave = functionRepo.Find(c => c.FunctionName != string.Empty).Count;

            ICollection <IFunction> functionList = new List <IFunction>();

            functionRepo.Save(functionList);

            var afterEmptySave = functionRepo.Find(c => c.FunctionName != string.Empty).Count;

            Assert.AreEqual(beforeEmptySave, afterEmptySave);
        }