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 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);
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
        public void Function_NullDescriptionAndArguments_Expected_FunctionStillCreated()
        {
            const string functionName = "Test Function";

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

            Assert.IsNotNull(func);
        }
예제 #5
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);
        }
예제 #6
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);
        }
예제 #7
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);
        }
예제 #8
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));
        }
예제 #9
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);
        }
예제 #10
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);
            }
        }
예제 #11
0
        public void CreateCustomFunction_NullFunc_Expected_ExceptionReturned()
        {
            const string functionName = "TestFunction";
            var          arguments    = new List <string> {
                "x", "y"
            };
            var argumentDescriptions = new List <string> {
                "the first argument", "the second argument"
            };
            const string description = "My TestFunction";

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

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

            Assert.AreEqual("TestFunction", func.FunctionName);
        }
예제 #12
0
        public void CreateCustomFunction_AllValidValues_Expected_CustomFunctionCreatedAndRegisteredWithCalcManager()
        {
            const string  functionName = "TestFunction";
            List <string> arguments    = new List <string> {
                "x", "y"
            };
            List <string> argumentDescriptions = new List <string> {
                "the first argument", "the second argument"
            };
            const string description = "My TestFunction";

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

            func.CreateCustomFunction(functionName, arguments, argumentDescriptions, description, function, manager);
            CalculationValue value = manager.CalculateFormula("TestFunction(1)");

            Assert.AreEqual(123123423423, value.ToDouble());
        }
        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)));
        }