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);
        }
Esempio n. 2
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 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);
        }
        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);
        }
        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_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_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_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_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);
        }
        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);
        }
        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);
        }
        public void FunctionRepository_Save_NullFunction_Expected_ArgumentNullException()
        {
            var functionRepo = MathOpsFactory.FunctionRepository();

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

            try
            {
                functionRepo.Save((IFunction)null);
            }
            catch (ArgumentNullException)
            {
                // If there was a null argument exception, it's behaving
                Assert.IsTrue(true);
            }
        }
        public CalculateIntellisenseProvider(ISyntaxTreeBuilderHelper syntaxTreeBuilderHelper)
        {
            _syntaxTreeBuilderHelper = syntaxTreeBuilderHelper;
            IntellisenseProviderType = IntellisenseProviderType.NonDefault;
            var functionList = MathOpsFactory.FunctionRepository();

            functionList.Load();
            IntellisenseResult = functionList.All().Select(currentFunction =>
            {
                var description         = currentFunction.Description;
                var dropDownDescription = description;
                if (description != null && description.Length > 80)
                {
                    dropDownDescription = description.Substring(0, 77) + "...";
                }
                _functionNames.Add(currentFunction.FunctionName);

                var result = new IntellisenseProviderResult(this, currentFunction.FunctionName, dropDownDescription, description, currentFunction.arguments?.ToArray() ?? new string[0], currentFunction.ArgumentDescriptions?.ToArray() ?? new string[0]);
                return(result);
            }).OrderBy(p => p.Name).ToList();
        }
        public void FunctionRepository_Save_ValidFunction_Expected_RepoUpdatedWithNewFunction()
        {
            var          functionRepo = MathOpsFactory.FunctionRepository();
            const string functionName = "TestFunction";
            var          arguments    = new List <string> {
                "args"
            };
            var argumentDescriptions = new List <string> {
                "the first argument"
            };
            const string description = "Test Description";

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


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

            functionRepo.Save(myFunction);

            Assert.IsNotNull(functionRepo.Find(c => c.FunctionName.Equals(functionName)));
        }