Implementation of IValidationAction that allows you to define Spring.NET expressions that should be evaluated after validation.
Inheritance: BaseValidationAction
        public void WhenInvalid()
        {
            Inventor context = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");
            Dictionary <string, object> vars = new Dictionary <string, object>();

            ExpressionAction action = new ExpressionAction("#result = 'valid'", "#result = 'invalid'");

            action.Execute(false, context, vars, null);
            Assert.AreEqual("invalid", vars["result"]);

            action = new ExpressionAction(Expression.Parse("#result = Name"), Expression.Parse("#result = Nationality"));
            action.Execute(false, context, vars, null);
            Assert.AreEqual(context.Nationality, vars["result"]);

            action         = new ExpressionAction();
            action.Valid   = Expression.Parse("#result = DOB.Year");
            action.Invalid = Expression.Parse("#result = DOB.Month");
            action.Execute(false, context, vars, null);
            Assert.AreEqual(context.DOB.Month, vars["result"]);

            vars.Clear();
            action = new ExpressionAction("#result = 'valid'", null);
            action.Execute(false, context, vars, null);
            Assert.IsFalse(vars.ContainsKey("result"), "Result should not exist when invalid expression is null.");
        }
        public void WhenValid()
        {
            Inventor    context = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");
            IDictionary vars    = new Hashtable();

            ExpressionAction action = new ExpressionAction("#result = 'valid'", "#result = 'invalid'");

            action.Execute(true, context, vars, null);
            Assert.AreEqual("valid", vars["result"]);

            action = new ExpressionAction(Expression.Parse("#result = Name"), Expression.Parse("#result = Nationality"));
            action.Execute(true, context, vars, null);
            Assert.AreEqual(context.Name, vars["result"]);

            action         = new ExpressionAction();
            action.Valid   = Expression.Parse("#result = DOB.Year");
            action.Invalid = Expression.Parse("#result = DOB.Month");
            action.Execute(true, context, vars, null);
            Assert.AreEqual(context.DOB.Year, vars["result"]);

            vars.Clear();
            action = new ExpressionAction(null, "#result = 'invalid'");
            action.Execute(true, context, vars, null);
            Assert.IsFalse(vars.Contains("result"), "Result should not exist when valid expression is null.");
        }
Exemplo n.º 3
0
        public void WhenActionIsNotExecutedBecauseWhenExpressionReturnsFalse()
        {
            Inventor context = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");
            Dictionary <string, object> vars = new Dictionary <string, object>();

            ExpressionAction action = new ExpressionAction("#result = 'valid'", "#result = 'invalid'");

            action.When = Expression.Parse("false");
            action.Execute(true, context, vars, null);
            Assert.IsFalse(vars.ContainsKey("result"));
        }
        public void WhenInvalid()
        {
            Inventor context = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");
            Dictionary<string, object> vars = new Dictionary<string, object>();

            ExpressionAction action = new ExpressionAction("#result = 'valid'", "#result = 'invalid'");
            action.Execute(false, context, vars, null);
            Assert.AreEqual("invalid", vars["result"]);

            action = new ExpressionAction(Expression.Parse("#result = Name"), Expression.Parse("#result = Nationality"));
            action.Execute(false, context, vars, null);
            Assert.AreEqual(context.Nationality, vars["result"]);

            action = new ExpressionAction();
            action.Valid = Expression.Parse("#result = DOB.Year");
            action.Invalid = Expression.Parse("#result = DOB.Month");
            action.Execute(false, context, vars, null);
            Assert.AreEqual(context.DOB.Month, vars["result"]);

            vars.Clear();
            action = new ExpressionAction("#result = 'valid'", null);
            action.Execute(false, context, vars, null);
            Assert.IsFalse(vars.ContainsKey("result"), "Result should not exist when invalid expression is null.");
        }
        public void WhenValid()
        {
            Inventor context = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");
            IDictionary vars = new Hashtable();

            ExpressionAction action = new ExpressionAction("#result = 'valid'", "#result = 'invalid'");
            action.Execute(true, context, vars, null);
            Assert.AreEqual("valid", vars["result"]);

            action = new ExpressionAction(Expression.Parse("#result = Name"), Expression.Parse("#result = Nationality"));
            action.Execute(true, context, vars, null);
            Assert.AreEqual(context.Name, vars["result"]);

            action = new ExpressionAction();
            action.Valid = Expression.Parse("#result = DOB.Year");
            action.Invalid = Expression.Parse("#result = DOB.Month");
            action.Execute(true, context, vars, null);
            Assert.AreEqual(context.DOB.Year, vars["result"]);

            vars.Clear();
            action = new ExpressionAction(null, "#result = 'invalid'");
            action.Execute(true, context, vars, null);
            Assert.IsFalse(vars.Contains("result"), "Result should not exist when valid expression is null.");
        }
        public void WhenActionIsNotExecutedBecauseWhenExpressionReturnsFalse()
        {
            Inventor context = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");
            IDictionary vars = new Hashtable();

            ExpressionAction action = new ExpressionAction("#result = 'valid'", "#result = 'invalid'");
            action.When = Expression.Parse("false");
            action.Execute(true, context, vars, null);
            Assert.IsFalse(vars.Contains("result"));
        }