Exemplo n.º 1
0
        private static IDictionary ResolveToDictionary(VariableExpression expression, IBindingEnvironment environment)
        {
            string name = expression.VariableName;

            object obj = environment.GetValue(name);

            if (obj == null)
            {
                obj = new Hashtable();

                // TODO Review if Local or not
                environment.SetValue(name, obj);
            }

            return (IDictionary)obj;
        }
Exemplo n.º 2
0
 private static void SetValue(VariableExpression expression, object value, IBindingEnvironment environment)
 {
     environment.SetValue(expression.VariableName, value);
 }
Exemplo n.º 3
0
        private static object ResolveToObject(VariableExpression expression, IBindingEnvironment environment)
        {
            string name = expression.VariableName;

            object obj = environment.GetValue(name);

            if (obj == null)
            {
                obj = new DynamicObject();

                // TODO Review if Local or not
                environment.SetValue(name, obj);
            }

            return obj;
        }
Exemplo n.º 4
0
        public void UndefinedVariableIsNull()
        {
            BindingEnvironment environment = new BindingEnvironment();
            VariableExpression var = new VariableExpression("foo");

            Assert.IsNull(var.Evaluate(environment));
        }
Exemplo n.º 5
0
        public void EvaluateVariableExpressions()
        {
            BindingEnvironment environment = new BindingEnvironment();

            environment.SetValue("foo", "bar");
            environment.SetValue("one", 1);

            VariableExpression varFoo = new VariableExpression("foo");
            VariableExpression varOne = new VariableExpression("one");

            Assert.AreEqual("bar", varFoo.Evaluate(environment));
            Assert.AreEqual(1, varOne.Evaluate(environment));
        }
Exemplo n.º 6
0
        public void ResolveVariableExpressionToDictionary()
        {
            BindingEnvironment environment = new BindingEnvironment();
            IExpression expression = new VariableExpression("foo");

            object obj = ExpressionUtilities.ResolveToDictionary(expression, environment);

            Assert.IsNotNull(obj);
            Assert.IsInstanceOfType(obj, typeof(IDictionary));

            Assert.AreEqual(obj, environment.GetValue("foo"));
        }
Exemplo n.º 7
0
        public void ExecuteWhileCommand()
        {
            IExpression incrementX = new ArithmeticBinaryExpression(ArithmeticOperator.Add, new ConstantExpression(1), new VariableExpression("x"));
            IExpression decrementY = new ArithmeticBinaryExpression(ArithmeticOperator.Subtract, new VariableExpression("y"), new ConstantExpression(1));
            ICommand setX = new SetVariableCommand("x", incrementX);
            ICommand setY = new SetVariableCommand("y", decrementY);
            List<ICommand> commands = new List<ICommand>();
            commands.Add(setX);
            commands.Add(setY);
            ICommand command = new CompositeCommand(commands);
            IExpression yexpr = new VariableExpression("y");

            WhileCommand whilecmd = new WhileCommand(yexpr, command);

            BindingEnvironment environment = new BindingEnvironment();

            environment.SetValue("x", 0);
            environment.SetValue("y", 5);

            whilecmd.Execute(environment);

            Assert.AreEqual(0, environment.GetValue("y"));
            Assert.AreEqual(5, environment.GetValue("x"));
        }