Ejemplo n.º 1
0
        public void EvaluateExpressions_NullExpressions()
        {
            var handler = new CalcEngineRequestHandler();

            Assert.That(() => handler.EvaluateExpressions(new EntityType(), null),
                        Throws.TypeOf <ArgumentNullException>().And.Property("ParamName").EqualTo("expressions"));
        }
Ejemplo n.º 2
0
        public void EvaluateExpressions_EvalSingleExpression()
        {
            var handler = new CalcEngineRequestHandler();

            var entity = new EntityType
            {
                Name        = Guid.NewGuid().ToString(),
                Description = Guid.NewGuid().ToString()
            };

            var expressions = new Dictionary <string, CalcEngineExpression>
            {
                {
                    "GetName",
                    new CalcEngineExpression
                    {
                        ExpectedResultType = new ExpressionType
                        {
                            DataType = DataType.String
                        },
                        Expression = "[Name]"
                    }
                }
            };

            var results = handler.EvaluateExpressions(entity, expressions);

            Assert.IsNotNull(results);
            Assert.AreEqual(1, results.Results.Count);
            Assert.IsTrue(results.Results.ContainsKey("GetName"));
            Assert.AreEqual(entity.Name, results.Results["GetName"].Value);
            Assert.AreEqual(DataType.String, results.Results["GetName"].ResultType);
        }
Ejemplo n.º 3
0
        public void EvaluateExpressions_EvalMultipleExpressionsWithFailures()
        {
            var handler = new CalcEngineRequestHandler();

            var entity = new EntityType
            {
                Name        = Guid.NewGuid().ToString(),
                Description = Guid.NewGuid().ToString()
            };

            var expressions = new Dictionary <string, CalcEngineExpression>
            {
                {
                    "GetName",
                    new CalcEngineExpression
                    {
                        ExpectedResultType = new ExpressionType
                        {
                            DataType = DataType.String
                        },
                        Expression = "XXXXXX!!!"
                    }
                },
                {
                    "GetDescription",
                    new CalcEngineExpression
                    {
                        ExpectedResultType = new ExpressionType
                        {
                            DataType = DataType.String
                        },
                        Expression = "[Description]"
                    }
                }
            };

            var results = handler.EvaluateExpressions(entity, expressions);

            Assert.IsNotNull(results);
            Assert.AreEqual(2, results.Results.Count);
            Assert.IsTrue(results.Results.ContainsKey("GetName"));
            Assert.IsFalse(string.IsNullOrWhiteSpace(results.Results["GetName"].ErrorMessage));
            Assert.IsTrue(string.IsNullOrWhiteSpace(results.Results["GetName"].Value));

            Assert.IsTrue(results.Results.ContainsKey("GetDescription"));
            Assert.IsTrue(string.IsNullOrWhiteSpace(results.Results["GetDescription"].ErrorMessage));
            Assert.AreEqual(entity.Description, results.Results["GetDescription"].Value);
            Assert.AreEqual(DataType.String, results.Results["GetDescription"].ResultType);
        }