Ejemplo n.º 1
0
        public void Instantiate_NCalcArgs_NcalcResolver()
        {
            var context = new Context(null);
            var args    = new NCalcScalarResolverArgs("a * b - 2", context);

            var factory  = new ScalarResolverFactory(null);
            var resolver = factory.Instantiate(args);

            Assert.That(resolver, Is.TypeOf <NCalcScalarResolver <object> >());
        }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
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));
            }
        }
Ejemplo n.º 4
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));
            }
        }
Ejemplo n.º 5
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));
            }
        }