예제 #1
0
        public Interpreter(IGenericHelper genericHelper, IFunctionHelper functionHelper,
                           IIntegerHelper integerHelper, IRealHelper realHelper,
                           IBooleanHelper booleanHelper, ISetHelper setHelper,
                           IElementHelper elementHelper, IStringHelper stringHelper,
                           IGraphHelper graphHelper, bool catchExceptions)
        {
            _catchExceptions = catchExceptions;
            _exceptions      = new ComponentException();
            _functionHelper  = functionHelper;

            _integerHelper = integerHelper;
            _integerHelper.SetInterpreter(this);

            _realHelper = realHelper;
            _realHelper.SetInterpreter(this);

            _booleanHelper = booleanHelper;
            _booleanHelper.SetInterpreter(this);

            _genericHelper = genericHelper;
            _genericHelper.SetInterpreter(this);

            _setHelper = setHelper;
            _setHelper.SetInterpreter(this);

            _elementHelper = elementHelper;
            _elementHelper.SetInterpreter(this);

            _stringHelper = stringHelper;
            _stringHelper.SetInterpreter(this);

            _graphHelper = graphHelper;
            _graphHelper.SetInterpreter(this);
        }
예제 #2
0
 public FileController(IFileDataModel fileDataModel, ILogger logger, IMessageQueueHelper messageQueueHelper, IApplicationConfig applicationConfig, IFileUploadHelper fileUploadHelper, IGenericHelper genericHelper)
 {
     this._fileDataModel      = fileDataModel;
     this._logger             = logger;
     this._messageQueueHelper = messageQueueHelper;
     this._applicationConfig  = applicationConfig;
     this._fileUploadHelper   = fileUploadHelper;
     this._genericHelper      = genericHelper;
 }
예제 #3
0
        public static Interpreter GetIntepreterOnlyWith(IBooleanHelper booleanHelper)
        {
            IFunctionHelper functionHelper = Substitute.For <IFunctionHelper>();
            IIntegerHelper  integerHelper  = Substitute.For <IIntegerHelper>();
            IRealHelper     realHelper     = Substitute.For <IRealHelper>();
            IGenericHelper  genericHelper  = Substitute.For <IGenericHelper>();
            ISetHelper      setHelper      = Substitute.For <ISetHelper>();
            IElementHelper  elemHelper     = Substitute.For <IElementHelper>();
            IStringHelper   stringHelper   = Substitute.For <IStringHelper>();
            IGraphHelper    graphHelper    = Substitute.For <IGraphHelper>();

            return(new Interpreter(genericHelper, functionHelper, integerHelper, realHelper, booleanHelper, setHelper, elemHelper, stringHelper, graphHelper, false));
        }
        public void DispatchBool_ReturnsCorrect_Indentifier(bool expected)
        {
            var            node        = GetIdentifierExp();
            IGenericHelper boolHelper  = Substitute.For <IGenericHelper>();
            Interpreter    interpreter = Utilities.GetIntepreterOnlyWith(boolHelper);

            boolHelper.Identifier <bool>(Arg.Any <IdentifierExpression>(), Arg.Any <List <object> >())
            .Returns(expected);

            bool res = interpreter.DispatchBoolean(node, new List <Object>());

            Assert.AreEqual(res, expected);
        }
        public void DispatchBool_Identifier_PassParametersDown(object o)
        {
            var parameters = GetParameterList();
            var node       = GetIdentifierExp();

            IGenericHelper boolHelper  = Substitute.For <IGenericHelper>();
            Interpreter    interpreter = Utilities.GetIntepreterOnlyWith(boolHelper);
            List <object>  res         = null;

            boolHelper.Identifier <bool>(Arg.Any <IdentifierExpression>(), Arg.Do <List <object> >(x => res = x))
            .Returns(true);

            interpreter.DispatchBoolean(node, parameters.ToList());

            res.Should().BeEquivalentTo(parameters);
        }
        public void DispatchBool_Identifier_PassNodeDown()
        {
            var parameters = GetParameterList();
            var node       = GetIdentifierExp();
            var expected   = node;

            IGenericHelper boolHelper  = Substitute.For <IGenericHelper>();
            Interpreter    interpreter = Utilities.GetIntepreterOnlyWith(boolHelper);
            Node           res         = null;

            boolHelper.Identifier <bool>(Arg.Do <IdentifierExpression>(x => res = x), Arg.Any <List <object> >())
            .Returns(true);
            interpreter.DispatchBoolean(node, parameters);

            Assert.AreEqual(expected, res);
        }
예제 #7
0
        public void FunctionInteger_FunctionNodeAndObjectList_CorrectValueReturned()
        {
            int           expected = 17;
            FunctionNode  input1   = new FunctionNode("", new ConditionNode(null, 0, 0), null, null, 0, 0);
            List <Object> input2   = new List <Object>()
            {
                23, 2.334, null
            };
            IGenericHelper ihelper     = Substitute.For <IGenericHelper>();
            Interpreter    interpreter = Utilities.GetIntepreterOnlyWith(ihelper);

            ihelper.Condition <int>(Arg.Any <ConditionNode>(), Arg.Any <List <Object> >()).Returns(new MatchPair <int>(true, expected));

            int res = (int)interpreter.Function <int>(input1, input2);

            Assert.AreEqual(expected, res);
        }
예제 #8
0
        public void DispatchInteger_FunctionCallAndObjectList_CorrectValueReturned()
        {
            int expected = 17;
            FunctionCallExpression input1 = new FunctionCallExpression("", null, 0, 0);
            List <Object>          input2 = new List <Object>()
            {
                23, 2.334, null
            };
            IGenericHelper ihelper     = Substitute.For <IGenericHelper>();
            Interpreter    interpreter = Utilities.GetIntepreterOnlyWith(ihelper);

            ihelper.FunctionCall <int>(Arg.Any <FunctionCallExpression>(), Arg.Any <List <Object> >()).Returns(expected);

            int res = interpreter.DispatchInt(input1, input2);

            Assert.AreEqual(expected, res);
        }
예제 #9
0
        public void DispatchInteger_FunctionCallAndObjectList_CorrectListPassed()
        {
            List <Object> expected = new List <Object>()
            {
                23, 2.334, null
            };
            FunctionCallExpression input1      = new FunctionCallExpression("", null, 0, 0);
            IGenericHelper         ihelper     = Substitute.For <IGenericHelper>();
            Interpreter            interpreter = Utilities.GetIntepreterOnlyWith(ihelper);
            List <Object>          res         = null;

            ihelper.FunctionCall <int>(Arg.Any <FunctionCallExpression>(), Arg.Do <List <Object> >(x => res = x));

            interpreter.DispatchInt(input1, expected);

            res.Should().BeEquivalentTo(expected);
        }
        public void DispatchReal_IdentifierAndObjectList_CorrectValueReturned()
        {
            double expected             = 17;
            IdentifierExpression input1 = new IdentifierExpression(null, 0, 0);
            List <Object>        input2 = new List <Object>()
            {
                23, 2.334, null
            };
            IGenericHelper rhelper     = Substitute.For <IGenericHelper>();
            Interpreter    interpreter = Utilities.GetIntepreterOnlyWith(rhelper);

            rhelper.Identifier <double>(Arg.Any <IdentifierExpression>(), Arg.Any <List <Object> >()).Returns(expected);

            double res = interpreter.DispatchReal(input1, input2);

            Assert.AreEqual(expected, res);
        }
        public void DispatchReal_IdentifierAndObjectList_CorrectListPassed()
        {
            List <Object> expected = new List <Object>()
            {
                23, 2.334, null
            };
            IdentifierExpression input1      = new IdentifierExpression(null, 0, 0);
            IGenericHelper       rhelper     = Substitute.For <IGenericHelper>();
            Interpreter          interpreter = Utilities.GetIntepreterOnlyWith(rhelper);
            List <Object>        res         = null;

            rhelper.Identifier <double>(Arg.Any <IdentifierExpression>(), Arg.Do <List <Object> >(x => res = x));

            interpreter.DispatchReal(input1, expected);

            res.Should().BeEquivalentTo(expected);
        }
        public void DispatchInteger_IdentifierAndObjectList_CorrectIdentifierExprPassed()
        {
            IdentifierExpression expected = new IdentifierExpression(null, 0, 0);
            IdentifierExpression input1   = expected;
            List <Object>        input2   = new List <Object>()
            {
                23, 2.334, null
            };
            IGenericHelper       ihelper     = Substitute.For <IGenericHelper>();
            Interpreter          interpreter = Utilities.GetIntepreterOnlyWith(ihelper);
            IdentifierExpression res         = null;

            ihelper.Identifier <int>(Arg.Do <IdentifierExpression>(x => res = x), Arg.Any <List <Object> >());

            interpreter.DispatchInt(input1, input2);

            res.Should().BeEquivalentTo(expected);
        }
예제 #13
0
        public void FunctionInteger_FunctionNodeAndObjectList_CorrectListPassed()
        {
            List <Object> expected = new List <Object>()
            {
                23, 2.334, null
            };
            FunctionNode   input1      = new FunctionNode("", new ConditionNode(null, 0, 0), null, null, 0, 0);
            IGenericHelper ihelper     = Substitute.For <IGenericHelper>();
            Interpreter    interpreter = Utilities.GetIntepreterOnlyWith(ihelper);
            List <Object>  res         = null;

            ihelper.Condition <int>(Arg.Any <ConditionNode>(),
                                    Arg.Do <List <Object> >(x => res = x)).
            Returns(new MatchPair <int>(true, 1));

            interpreter.Function <int>(input1, expected);

            res.Should().BeEquivalentTo(expected);
        }
예제 #14
0
        public void FunctionInteger_FunctionNodeAndTwoConditionAndObjectList_CorrectExceptionThrown()
        {
            ConditionNode cn1    = new ConditionNode(new BooleanLiteralExpression(true, 0, 0), null, 0, 0);
            ConditionNode cn2    = new ConditionNode(new BooleanLiteralExpression(true, 0, 0), null, 0, 0);
            FunctionNode  input1 = new FunctionNode(new List <ConditionNode> {
                cn1, cn2
            }, "", null, null, 0, 0);
            List <Object> input2 = new List <Object>()
            {
                23, 2.334, null
            };
            IGenericHelper fhelper     = Substitute.For <IGenericHelper>();
            Interpreter    interpreter = Utilities.GetIntepreterOnlyWith(fhelper);

            fhelper.Condition <int>(cn1, Arg.Any <List <Object> >()).Returns(new MatchPair <int>(true, 17));
            fhelper.Condition <int>(cn2, Arg.Any <List <Object> >()).Returns(new MatchPair <int>(true, 18));


            Assert.ThrowsException <ComponentException>(() => interpreter.Function <int>(input1, input2));
        }
예제 #15
0
        public void FunctionInteger_FunctionNodeAndTwoConditionsOneDefaultCaseAndObjectList_CorrectValueReturned(bool aValid, int a, bool bValid, int b, int expected)
        {
            ConditionNode cn1    = new ConditionNode(new BooleanLiteralExpression(true, 0, 0), null, 0, 0);
            ConditionNode cn2    = new ConditionNode(null, 0, 0);
            FunctionNode  input1 = new FunctionNode(new List <ConditionNode> {
                cn1, cn2
            }, "", null, null, 0, 0);
            List <Object> input2 = new List <Object>()
            {
                23, 2.334, null
            };
            IGenericHelper fhelper     = Substitute.For <IGenericHelper>();
            Interpreter    interpreter = Utilities.GetIntepreterOnlyWith(fhelper);

            fhelper.Condition <int>(cn1, Arg.Any <List <Object> >()).Returns(new MatchPair <int>(aValid, a));
            fhelper.Condition <int>(cn2, Arg.Any <List <Object> >()).Returns(new MatchPair <int>(bValid, b));

            int res = (int)interpreter.Function <int>(input1, input2);

            Assert.AreEqual(expected, res);
        }