Пример #1
0
 protected override ResultSet Execute(ResultSet rs, int ordinal)
 {
     foreach (DataRow row in rs.Rows)
     {
         Context.Switch(row);
         var args     = new NCalcScalarResolverArgs(Code, Context);
         var resolver = new NCalcScalarResolver <object>(args);
         row[ordinal] = resolver.Execute();
     }
     return(rs);
 }
Пример #2
0
        public void Instantiate_WithoutRowValues_CorrectComputation()
        {
            using (var dt = new DataTable())
            {
                var row     = dt.NewRow();
                var context = new Context(null);
                var args    = new NCalcScalarResolverArgs("1+1", context);
                context.Switch(row);
                var resolver = new NCalcScalarResolver <object>(args);

                var output = resolver.Execute();

                Assert.That(output, Is.EqualTo(2));
            }
        }
Пример #3
0
        public void Instantiate_WithRowValuesBasedOnOrdinals_CorrectComputation()
        {
            using (var dt = new DataTable())
            {
                dt.Columns.Add("a", typeof(int));
                dt.Columns.Add("b", typeof(int));
                dt.Columns.Add("c", typeof(int));
                var row = dt.NewRow();
                row.ItemArray = new object[] { 2, 5, 3 };
                var context = new Context(null);
                var args    = new NCalcScalarResolverArgs("[#0]*Max([#1], [#2])-2", context);
                context.Switch(row);
                var resolver = new NCalcScalarResolver <object>(args);

                var output = resolver.Execute();

                Assert.That(output, Is.EqualTo(2 * Math.Max(5, 3) - 2));
            }
        }
Пример #4
0
        public void Instantiate_WithRowValuesBasedOnOrdinalsAndVariable_CorrectComputation()
        {
            using (var dt = new DataTable())
            {
                dt.Columns.Add("a", typeof(int));
                dt.Columns.Add("b", typeof(int));
                dt.Columns.Add("c", typeof(int));
                var row = dt.NewRow();
                row.ItemArray = new object[] { 2, 5, 3 };
                var context = new Context(new Dictionary <string, ITestVariable> {
                    { "myVar", new GlobalVariable(new LiteralScalarResolver <decimal>(10)) }
                });
                var args = new NCalcScalarResolverArgs("[#0]*Max([#1], [#2])-[@myVar]", context);
                context.Switch(row);
                var resolver = new NCalcScalarResolver <object>(args);

                var output = resolver.Execute();

                Assert.That(output, Is.EqualTo(2 * Math.Max(5, 3) - 10));
            }
        }