public void Concat_UserId_String ()
		{
			string expression = "User!Language + ' is my motherlanguage'";
			var compiler = new ReportingLanguageCompiler();
			IExpression compiled = compiler.CompileExpression<object>(expression);
			Assert.That(compiled.Evaluate(null), Is.EqualTo("deu is my motherlanguage"));
		}
		public void Concat_Three_Strings ()
		{
			string expression = "'Sharp' + 'Develop' + 'Reporting'";
			var compiler = new ReportingLanguageCompiler();
			IExpression compiled = compiler.CompileExpression<object>(expression);
			Assert.That(compiled.Evaluate(null), Is.EqualTo("SharpDevelopReporting"));
		}
		public void Concat_String_UserId ()
		{
			string expression = "'Hello:' + User!UserId";
			var compiler = new ReportingLanguageCompiler();
			IExpression compiled = compiler.CompileExpression<object>(expression);
			Assert.That(compiled.Evaluate(null), Is.EqualTo("Hello:" + Environment.UserName));
		}
 public void Can_Compile_Simple_Variable()
 {
     const string expression = "varName";
     var compiler = new ReportingLanguageCompiler();
     IExpression compiled = compiler.CompileExpression<string>(expression);
     Assert.That(compiled.Evaluate(null), Is.EqualTo("varName"));
 }
 public void Can_Compile_Unary_Expression()
 {
     const string expression = "!true";
     var compiler = new ReportingLanguageCompiler();
     IExpression expr = compiler.CompileExpression<bool>(expression);
     Assert.That(expr.Evaluate(null), Is.False);
 }
 public void Can_Compile_Simple_String_As_bool()
 {
     const string expression = "'tRue'";
     var compiler = new ReportingLanguageCompiler();
     IExpression compiled = compiler.CompileExpression<bool>(expression);
     Assert.That(compiled.Evaluate(null), Is.EqualTo(true));
 }
		public void Concat_String_UserId_String_UserLan ()	
		{
			string expression = "'a' + User!Language + 'b' + User!Language";
			var compiler = new ReportingLanguageCompiler();
			IExpression compiled = compiler.CompileExpression<object>(expression);
			Assert.That(compiled.Evaluate(null), Is.EqualTo("adeubdeu"));
		}
 public void Can_Parse_Basic_Conditional_False_Result()
 {
     const string expression = "if (false) then 1";
     var compiler = new ReportingLanguageCompiler();
     IExpression expr = compiler.CompileExpression<int>(expression);
     Assert.That(expr.Evaluate(null), Is.EqualTo(0));
 }
 public void Can_Compile_Simple_Number()
 {
     const string expression = "1.1";
     var compiler = new ReportingLanguageCompiler();;
     IExpression compiled = compiler.CompileExpression<double>(expression);
     Assert.That(compiled.Evaluate(null), Is.EqualTo(1.1));
 }
 public void Can_Parse_If_Then_Else_In_Complex_Context()
 {
     const string expression = "2 * (if (true) then 9 otherwise 5 + 3)^2";
     var compiler = new ReportingLanguageCompiler();
     IExpression expr = compiler.CompileExpression<int>(expression);
     Assert.That(expr.Evaluate(null),Is.EqualTo(288));
 }
 public void Can_Parse_If_Then_Else()
 {
     const string expression = "if (false) then 1 else 2";
     var compiler = new ReportingLanguageCompiler();
     IExpression expr = compiler.CompileExpression<int>(expression);
     Assert.That(expr.Evaluate(null), Is.EqualTo(2));
 }
 public void Can_Parse_If_Then_Else_2()
 {
     const string expression = "if (true) then 'red' else 'black'";
     var compiler = new ReportingLanguageCompiler();
     IExpression expr = compiler.CompileExpression<string>(expression);
     Assert.That(expr.Evaluate(null), Is.EqualTo("red"));
 }
		public ExpressionEvaluatorFacade()
		{
			compiler = new ReportingLanguageCompiler();
			this.context = new ExpressionContext(null);
			context.ResolveUnknownVariable += VariableStore;
			context.ResolveMissingFunction += FunctionStore;
		}
 public void Can_Compile_Simple_String()
 {
     const string expression = "'SharpReport'";
     var compiler = new ReportingLanguageCompiler();
     IExpression compiled = compiler.CompileExpression<string>(expression);
     Assert.That(compiled.Evaluate(null), Is.EqualTo("SharpReport"));
 }
Exemple #15
0
		public void Can_Divide_Two_Numbers_With_Double_Parenthesis ()
		{
			string expression = "(21 / 3) + (2 * 5)";
			var compiler = new ReportingLanguageCompiler();
			IExpression compiled = compiler.CompileExpression<object>(expression);
			Assert.That(compiled.Evaluate(null), Is.EqualTo(17.0));
		}
 public void Can_Compile_DateAdd()
 {
     const string expression = "dateAdd(today(),d,1)";
     var compiler = new ReportingLanguageCompiler();
     IExpression expr = compiler.CompileExpression<object>(expression);
     Assert.That(expr.Evaluate(null), Is.EqualTo(DateTime.Today.AddDays(1)));
 }
 public void Can_Compile_Expr_With_Generic_Return()
 {
     const string expression = "Today()";
     var compiler = new ReportingLanguageCompiler();
     IExpression expr = compiler.CompileExpression<object>(expression);
     Assert.That(expr.Evaluate(null), Is.EqualTo(DateTime.Today));
 }
 public void Can_Compile_Function()
 {
     const string expression = "today()";
     var compiler = new ReportingLanguageCompiler();
     IExpression expr = compiler.CompileExpression<DateTime>(expression);
     Assert.That(expr.Evaluate(null), Is.EqualTo(DateTime.Today));
 }
Exemple #19
0
		public void Can_Divide_Two_Numbers ()
		{
			string expression = "21 / 3";
			var compiler = new ReportingLanguageCompiler();
			IExpression compiled = compiler.CompileExpression<object>(expression);
			Assert.That(compiled.Evaluate(null), Is.EqualTo(7.0));
		}
 public void Matches_All_Positive_Match()
 {
     var data = new[] { 1, 2, 3, 4 };
     var eStr = "matches_all(current,current >= 1)";
     var compiler = new ReportingLanguageCompiler();
     var expr = compiler.CompileExpression<bool>(eStr);
     Assert.That(expr.Evaluate(new ExpressionContext(data)), Is.EqualTo(true));
 }
		public void Concat_String_FuntResult ()	
		{
			string expression = "'peter = ' + (5 * 10)";
				
			var compiler = new ReportingLanguageCompiler();
			IExpression compiled = compiler.CompileExpression<object>(expression);
			Assert.That(compiled.Evaluate(null), Is.EqualTo("peter = 50"));
		}
 public void Average_Maintains_Precision()
 {
     var data = new[] {1.5, 2.0};
     var eStr = "avg()";
     var compiler = new ReportingLanguageCompiler();
     var expr = compiler.CompileExpression<double>(eStr);
     Assert.That(expr.Evaluate(new ExpressionContext(data)),Is.EqualTo(1.75));
 }
 public void Matches_Any_Negative_Match()
 {
     var data = new[] { 1, 2, 3, 4 };
     var eStr = "MatchesAny(nothing,current > 4)";
     var compiler = new ReportingLanguageCompiler();
     var expr = compiler.CompileExpression<bool>(eStr);
     Assert.That(expr.Evaluate(new ExpressionContext(data)), Is.EqualTo(false));
 }
 public void Array_Average()
 {
     var data = new[] {2, 4, 6};
     var eStr = "avg()";
     var compiler = new ReportingLanguageCompiler();
     var expr = compiler.CompileExpression<double>(eStr);
     Assert.That(expr.Evaluate(new ExpressionContext(data)), Is.EqualTo(4));
 }
 public void Array_Handles_Divide_By_Zero()
 {
     var data = new int[]{};
     var eStr = "average()";
     var compiler = new ReportingLanguageCompiler();
     var expr = compiler.CompileExpression<double>(eStr);
     Assert.That(expr.Evaluate(new ExpressionContext(data)), Is.EqualTo(0));
 }
 public void Array_Sum()
 {
     var data = new[] {1, 2, 4, 8, 16, 32, 64, 128};
     var eStr = "sum()";
     var compiler = new ReportingLanguageCompiler();
     var expr = compiler.CompileExpression<double>(eStr);
     Assert.That(expr.Evaluate(new ExpressionContext(data)), Is.EqualTo(255));
 }
        public void Can_Compile_Uknown_Variable()
        {
            const string expression = "varName";
            var compiler = new ReportingLanguageCompiler();
            IExpression compiled = compiler.CompileExpression<string>(expression);

            var context = new ExpressionContext(null);
            context.ResolveUnknownVariable += (sender, args) =>
                                                  {
                                                      Assert.That(args.VariableName, Is.EqualTo("varName"));
                                                      args.VariableValue = 123.456;
                                                  };
            Assert.That(compiled.Evaluate(context), Is.EqualTo("123,456"));

        }
 public void ItemAtIndex_Out_Of_Range_Position_Test()
 {
     var data = new[] { "a", "c", "f" };
     var eStr = "item_at_index(current,3)";
     var compiler = new ReportingLanguageCompiler();
     var expr = compiler.CompileExpression<string>(eStr);
     Assert.That(expr.Evaluate(new ExpressionContext(data)), Is.Null);
 }
 public void Array_Max()
 {
     var data = new[] { 10, 7, 3, 9 };
     var eStr = "max(current,current * 2)";
     var compiler = new ReportingLanguageCompiler();
     var expr = compiler.CompileExpression<int>(eStr);
     Assert.That(expr.Evaluate(new ExpressionContext(data)), Is.EqualTo(20));
 }
 public void Count_Simple_Integers()
 {
     var data = new[] { 1, 2, 3, 4 };
     var eStr = "count()";
     var compiler = new ReportingLanguageCompiler();
     var expr = compiler.CompileExpression<int>(eStr);
     Assert.That(expr.Evaluate(new ExpressionContext(data)), Is.EqualTo(4));
 }