Ejemplo n.º 1
0
        public void TestIssue1()
        {
            const string xml = @"
<add name='TestProcess'>
    <entities>
        <add name='TestData'>
            <rows>
                <add Pile='1Stories: 2Installed on: 09/14/2016 FSO: scpActual Appoi' />
            </rows>
            <fields>
                <add name='Pile' length='max'/>
            </fields>
            <calculated-fields>
                <add name='WithShorthand' t='copy(Pile).tolower().matching(installed on:\s*\d{1,2}\/\d{1,2}\/\d{2,4})' />
                <add name='WithLonghand'>
                  <transforms>
                     <add method='copy' value='Pile' />
                     <add method='tolower' />
                     <add method='matching' pattern='installed on:\s*\d{1,2}\/\d{1,2}\/\d{2,4}' />
                  </transforms>
                </add>
            </calculated-fields>
        </add>
    </entities>
</add>";

            var logger = new ConsoleLogger();

            using (var outer = new ConfigurationContainer().CreateScope(xml, logger)) {
                var process = outer.Resolve <Process>();
                using (var inner = new Container().CreateScope(process, logger)) {
                    var row           = inner.Resolve <IProcessController>().Read().ToArray()[0];
                    var withShorthand = process.Entities[0].CalculatedFields[0];
                    var withLonghand  = process.Entities[0].CalculatedFields[1];
                    Assert.AreEqual("installed on: 09/14/2016", row[withShorthand]);
                    Assert.AreEqual("installed on: 09/14/2016", row[withLonghand]);
                }
            }
        }
        public void DateDiff1()
        {
            var xml = @"
    <add name='TestProcess'>
      <entities>
        <add name='TestData' >
          <rows>
            <add StartDate='2016-06-01' EndDate='2016-08-01' />
          </rows>
          <fields>
            <add name='StartDate' type='datetime' />
            <add name='EndDate' type='datetime' />
          </fields>
          <calculated-fields>
            <add name='Years' type='int' t='copy(StartDate,EndDate).datediff(year)' />
            <add name='Days' type='int' t='copy(StartDate,EndDate).datediff(day)' />
            <add name='Minutes' type='int' t='copy(StartDate,EndDate).datediff(minute)' />
            <add name='Hours' type='double' t='copy(StartDate,EndDate).datediff(hour)' />
          </calculated-fields>
        </add>
      </entities>
    </add>
            ".Replace('\'', '"');

            var transform = new TransformHolder((c) => new DateDiffTransform(c), new DateDiffTransform().GetSignatures());

            using (var outer = new ConfigurationContainer(transform).CreateScope(xml, new DebugLogger())) {
                var process = outer.Resolve <Process>();
                using (var inner = new Container(transform).CreateScope(process, new DebugLogger())) {
                    var output = inner.Resolve <IProcessController>().Read().ToArray();
                    var cf     = process.Entities.First().CalculatedFields.ToArray();
                    Assert.AreEqual(0, output[0][cf[0]]);
                    Assert.AreEqual(61, output[0][cf[1]]);
                    Assert.AreEqual(87840, output[0][cf[2]]);
                    Assert.AreEqual(1464d, output[0][cf[3]]);
                }
            }
        }
Ejemplo n.º 3
0
        public void TryIt()
        {
            const string xml = @"
    <add name='TestProcess'>
        <connections>
            <add name='input' provider='internal' />
            <add name='output' provider='internal' />
        </connections>
      <entities>
        <add name='TestData'>
          <rows>
            <add input=' Wave 1' />
            <add input='Flight 1' />
          </rows>
          <fields>
            <add name='input' t='trim()' />
          </fields>
          <calculated-fields>
            <add name='output' type='bool' t='copy(input).startsWith(W)' />
          </calculated-fields>
        </add>
      </entities>
    </add>";


            var logger = new ConsoleLogger(LogLevel.Debug);

            using (var cfgScope = new ConfigurationContainer().CreateScope(xml, logger)) {
                var process = cfgScope.Resolve <Process>();

                using (var scope = new Container().CreateScope(process, logger)) {
                    var output = scope.Resolve <IProcessController>().Read().ToArray();

                    Assert.AreEqual(true, output[0][process.GetField("output")]);
                    Assert.AreEqual(false, output[1][process.GetField("output")]);
                }
            }
        }
        public void Join()
        {
            const string xml = @"
    <add name='TestProcess'>
      <entities>
        <add name='TestData'>
          <rows>
            <add Input1='2' Input2='4' Input3='6' />
          </rows>
          <fields>
            <add name='Input1' />
            <add name='Input2' />
            <add name='Input3' />
          </fields>
          <calculated-fields>
            <add name='Joined' t='copy(Input1,Input2,Input3).toArray().join(-)' />
          </calculated-fields>
        </add>
      </entities>
    </add>";

            var logger     = new ConsoleLogger(LogLevel.Debug);
            var transforms = new List <TransformHolder>()
            {
                new TransformHolder((c) => new JoinTransform(c), new JoinTransform().GetSignatures()),
                new TransformHolder((c) => new ToArrayTransform(c), new ToArrayTransform().GetSignatures())
            }.ToArray();

            using (var cfgScope = new ConfigurationContainer(transforms).CreateScope(xml, logger)) {
                var process = cfgScope.Resolve <Process>();

                using (var scope = new Container(transforms).CreateScope(process, logger)) {
                    scope.Resolve <IProcessController>().Execute();
                    var output = process.Entities.First().Rows;
                    Assert.AreEqual("2-4-6", output[0]["Joined"]);
                }
            }
        }
Ejemplo n.º 5
0
        public void EqualsValidator()
        {
            var xml = @"
    <add name='TestProcess'>
      <entities>
        <add name='TestData'>
          <rows>
            <add Field1='11' Field2='12' Field3='13' />
            <add Field1='11' Field2='11' Field3='11' />
          </rows>
          <fields>
            <add name='Field1' />
            <add name='Field2' />
            <add name='Field3' />
          </fields>
          <calculated-fields>
            <add name='AreEqual' type='bool' t='copy(Field1,Field2,Field3).equals()' />
            
          </calculated-fields>
        </add>
      </entities>
    </add>";


            var logger = new ConsoleLogger(LogLevel.Debug);

            using (var cfgScope = new ConfigurationContainer().CreateScope(xml, logger)) {
                var process = cfgScope.Resolve <Process>();

                using (var scope = new Container().CreateScope(process, logger)) {
                    var output = scope.Resolve <IProcessController>().Read().ToArray();

                    Assert.AreEqual(false, output[0][process.GetField("AreEqual")]);
                    Assert.AreEqual(true, output[1][process.GetField("AreEqual")]);
                }
            }
        }
Ejemplo n.º 6
0
        public void Tag()
        {
            const string xml = @"
    <add name='TestProcess'>
      <entities>
        <add name='TestData' pipeline='linq'>
          <rows>
            <add Field1='1' />
            <add Field1='5' />
          </rows>
          <fields>
            <add name='Field1' />
          </fields>
          <calculated-fields>
            <add name='span' t='copy(Field1).tag(span)' />
            <add name='div' t='copy(Field1).tag(div,class:fun)' />
          </calculated-fields>
        </add>
      </entities>
    </add>";

            var logger = new ConsoleLogger(LogLevel.Debug);

            using (var cfgScope = new ConfigurationContainer().CreateScope(xml, logger)) {
                var process = cfgScope.Resolve <Process>();

                using (var scope = new Container().CreateScope(process, logger)) {
                    var output = scope.Resolve <IProcessController>().Read().ToArray();

                    var cf = process.Entities.First().CalculatedFields.ToArray();
                    Assert.AreEqual("<span>1</span>", output[0][cf[0]]);
                    Assert.AreEqual("<div class=\"fun\">1</div>", output[0][cf[1]]);
                    Assert.AreEqual("<span>5</span>", output[1][cf[0]]);
                    Assert.AreEqual("<div class=\"fun\">5</div>", output[1][cf[1]]);
                }
            }
        }
Ejemplo n.º 7
0
        public void MakeSureTimeIsntChanging()
        {
            var xml = @"
    <add name='TestProcess'>
      <entities>
        <add name='TestData' >
          <rows>
            <add Date='2019-05-05 1:05 PM' />
          </rows>
          <fields>
            <add name='Date' type='datetime' />
          </fields>
          <calculated-fields>
            <add name='DateDefault' type='datetime' default='2019-05-05 1:07 PM' />
            <add name='DateWithZ' type='datetime' default='2019-05-05 1:08 PM Z' />
            <add name='DateWithOffSet' type='datetime' default='2019-05-05 1:09 PM +00:00' />
            <add name='DateWithOffSet4' type='datetime' default='2019-05-05 1:09 PM -04:00' />
          </calculated-fields>
        </add>
      </entities>
    </add>";

            var logger = new ConsoleLogger(LogLevel.Debug);

            using (var outer = new ConfigurationContainer().CreateScope(xml, logger)) {
                var process = outer.Resolve <Process>();
                using (var inner = new Container().CreateScope(process, logger)) {
                    inner.Resolve <IProcessController>().Execute();
                    var row = process.Entities.First().Rows.First();
                    Assert.AreEqual(new DateTime(2019, 5, 5, 13, 5, 0), row["Date"]);
                    Assert.AreEqual(new DateTime(2019, 5, 5, 13, 7, 0), row["DateDefault"]);
                    Assert.AreEqual(new DateTime(2019, 5, 5, 13, 8, 0), row["DateWithZ"]);
                    Assert.AreEqual(new DateTime(2019, 5, 5, 13, 9, 0), row["DateWithOffSet"]);
                    Assert.AreEqual(new DateTime(2019, 5, 5, 17, 9, 0), row["DateWithOffSet4"]);
                }
            }
        }
Ejemplo n.º 8
0
        public void In()
        {
            const string xml = @"
    <add name='TestProcess'>
      <entities>
        <add name='TestData' pipeline='linq'>
          <rows>
            <add Field1='1' />
            <add Field1='5' />
          </rows>
          <fields>
            <add name='Field1' />
          </fields>
          <calculated-fields>
            <add name='In123' type='bool' t='copy(Field1).in(1,2,3)' />
            <add name='In456' type='bool' t='copy(Field1).in(4,5,6)' />
          </calculated-fields>
        </add>
      </entities>
    </add>";

            var logger = new ConsoleLogger(LogLevel.Debug);

            using (var cfgScope = new ConfigurationContainer().CreateScope(xml, logger)) {
                var process = cfgScope.Resolve <Process>();

                using (var scope = new Container().CreateScope(process, logger)) {
                    var output = scope.Resolve <IProcessController>().Read().ToArray();

                    var cf = process.Entities.First().CalculatedFields.ToArray();
                    Assert.AreEqual(true, output[0][cf[0]]);
                    Assert.AreEqual(false, output[0][cf[1]]);
                    Assert.AreEqual(false, output[1][cf[0]]);
                    Assert.AreEqual(true, output[1][cf[1]]);
                }
            }
        }
Ejemplo n.º 9
0
        public void Test()
        {
            const string xml         = @"
<add name='TestProcess'>
    <entities>
        <add name='TestData'>
            <rows>
                <add Date='2019-07-01 10:30 AM' />
            </rows>
            <fields>
                <add name='Date' type='datetime'/>
            </fields>
            <calculated-fields>
                <add name='Milliseconds' type='long' t='copy(Date).timezone(Eastern Standard Time,UTC).tounixtime(ms)' />
                <add name='Seconds' type='long' t='copy(Date).timezone(Eastern Standard Time,UTC).tounixtime(seconds)' />
            </calculated-fields>
        </add>
    </entities>
</add>";
            var          logger      = new ConsoleLogger(LogLevel.Debug);
            var          specifyKind = new TransformHolder((c) => new TimeZoneTransform(c), new TimeZoneTransform().GetSignatures());
            var          toUnixTime  = new TransformHolder((c) => new ToUnixTimeTransform(c), new ToUnixTimeTransform().GetSignatures());

            using (var outer = new ConfigurationContainer(new[] { specifyKind, toUnixTime }).CreateScope(xml, logger)) {
                var process = outer.Resolve <Process>();
                using (var inner = new Container(new[] { specifyKind, toUnixTime }).CreateScope(process, logger)) {
                    var controller   = inner.Resolve <IProcessController>();
                    var output       = controller.Read().ToArray();
                    var milliseconds = (long)output[0][process.Entities.First().CalculatedFields.First()];
                    var seconds      = (long)output[0][process.Entities.First().CalculatedFields.Last()];

                    Assert.AreEqual(1561991400000, milliseconds);
                    Assert.AreEqual(1561991400, seconds);
                }
            }
        }
Ejemplo n.º 10
0
        public void Condense()
        {
            const string xml = @"
    <add name='TestProcess'>
      <entities>
        <add name='TestData' pipeline='linq'>
          <rows>
            <add Field1='Some  duplicates spa ces' />
            <add Field1='O n e  S p a c ee' />
          </rows>
          <fields>
            <add name='Field1' />
          </fields>
          <calculated-fields>
            <add name='CondenseField1' t='copy(Field1).condense()' />
            <add name='DuplicateE' t='copy(Field1).condense(e)' />
          </calculated-fields>
        </add>
      </entities>
    </add>";

            var logger = new ConsoleLogger(LogLevel.Debug);

            using (var outer = new ConfigurationContainer().CreateScope(xml, logger, null, "@()")) {
                var process = outer.Resolve <Process>();
                using (var inner = new Container().CreateScope(process, logger)) {
                    var results = inner.Resolve <IProcessController>().Read().ToArray();

                    var condensed = process.Entities.First().CalculatedFields.First();
                    var duplicate = process.Entities.First().CalculatedFields.Last();
                    Assert.AreEqual("Some duplicates spa ces", results[0][condensed]);
                    Assert.AreEqual("O n e S p a c ee", results[1][condensed]);
                    Assert.AreEqual("O n e  S p a c e", results[1][duplicate]);
                }
            }
        }
Ejemplo n.º 11
0
        public void Try()
        {
            var xml = @"
    <add name='TestProcess'>
      <entities>
        <add name='TestData' >
          <rows>
            <add Date1='2019-05-05 1:05 PM' Date2='2019-05-05 1:05 PM' Date3='2019-05-05 1:05 PM' Date4='2019-05-05 1:05 PM' Date5='2019-05-05T13:05:00Z' />
          </rows>
          <fields>
            <add name='Date1' type='datetime' t='specifyKind(unspecified)' />
            <add name='Date2' type='datetime' t='specifyKind(local)' />
            <add name='Date3' type='datetime' t='specifyKind(utc)' />
            <add name='Date4' type='datetime' />
            <add name='Date5' type='datetime' />
          </fields>
        </add>
      </entities>
    </add>";

            var logger    = new ConsoleLogger(LogLevel.Debug);
            var transform = new TransformHolder((c) => new SpecifyKindTransform(c), new SpecifyKindTransform().GetSignatures());

            using (var outer = new ConfigurationContainer(transform).CreateScope(xml, logger)) {
                var process = outer.Resolve <Process>();
                using (var inner = new Container(transform).CreateScope(process, logger)) {
                    inner.Resolve <IProcessController>().Execute();
                    var row = process.Entities.First().Rows.First();
                    Assert.AreEqual(DateTimeKind.Unspecified, ((DateTime)row["Date1"]).Kind);
                    Assert.AreEqual(DateTimeKind.Local, ((DateTime)row["Date2"]).Kind);
                    Assert.AreEqual(DateTimeKind.Utc, ((DateTime)row["Date3"]).Kind);
                    Assert.AreEqual(DateTimeKind.Unspecified, ((DateTime)row["Date4"]).Kind);
                    Assert.AreEqual(DateTimeKind.Utc, ((DateTime)row["Date5"]).Kind);
                }
            }
        }
        public void ToTime()
        {
            const string xml = @"
    <add name='TestProcess'>
      <entities>
        <add name='TestData'>
          <rows>
            <add intField='238' longField='500' />
          </rows>
          <fields>
            <add name='intField' type='int' />
            <add name='longField' type='long' />
          </fields>
          <calculated-fields>
            <add name='intFieldToTime' t='copy(intField).toTime(hour)' />
            <add name='longFieldToTime' t='copy(longField).toTime(seconds)' />
          </calculated-fields>
        </add>
      </entities>
    </add>";

            var logger = new ConsoleLogger(LogLevel.Debug);

            using (var outer = new ConfigurationContainer().CreateScope(xml, logger)) {
                var process = outer.Resolve <Process>();
                using (var inner = new Container().CreateScope(process, logger)) {
                    var results = inner.Resolve <IProcessController>().Read().ToArray();

                    var intFieldToTime  = process.Entities[0].CalculatedFields[0];
                    var longFieldToTime = process.Entities[0].CalculatedFields[1];

                    Assert.AreEqual("9.22:00:00", results[0][intFieldToTime]);
                    Assert.AreEqual("00:08:20", results[0][longFieldToTime]);
                }
            }
        }
        public void Run()
        {
            var logger = new ConsoleLogger();

            const string xml = @"
<add name='TestProcess'>
    <maps>
      <add name='map'>
         <items>
            <add from='1' to='One' />
            <add from='2' to='Two' />
            <add from='3' to='Three' />
         </items>
      </add>
    </maps>
    <entities>
        <add name='TestData'>
            <rows>
                <add number1='1' />
                <add number1='2' />
                <add number1='4' />
            </rows>
            <fields>
                <add name='number1' type='int' primary-key='true'>
                  <validators>
                     <add method='jint' script=""var x = number1+'' in map; if(x) { number1Message = map[number1];} else { number1Message = number1 + ' does not exist'}; x;"" />
                  </validators>
                </add>
            </fields>
        </add>
    </entities>

</add>";

            using (var outer = new ConfigurationContainer(new JintValidateModule()).CreateScope(xml, logger)) {
                var process = outer.Resolve <Process>();

                if (process.Errors().Any())
                {
                    foreach (var error in process.Errors())
                    {
                        System.Console.WriteLine(error);
                    }
                    return;
                }
                using (var inner = new Container(new JintValidateModule()).CreateScope(process, logger)) {
                    var controller = inner.Resolve <IProcessController>();
                    controller.Execute();
                    var rows = process.Entities.First().Rows;

                    Assert.AreEqual(true, rows[0]["number1Valid"]);
                    Assert.AreEqual("", rows[0]["number1Message"]);

                    Assert.AreEqual(true, rows[1]["number1Valid"]);
                    Assert.AreEqual("", rows[1]["number1Message"]);

                    Assert.AreEqual(false, rows[2]["number1Valid"]);
                    Assert.AreEqual("4 does not exist|", rows[2]["number1Message"]);
                }
            }
        }
Ejemplo n.º 14
0
        public void Run()
        {
            var logger = new ConsoleLogger();

            const string xml = @"
<add name='TestProcess'>
    <entities>
        <add name='TestData'>
            <rows>
                <add id='1' store='Walmart' other='' />
                <add id='2' store='Target' other='' />
                <add id='3' store='Other' other='' />
                <add id='4' store='Other' other='Costco' />
            </rows>
            <fields>
                <add name='id' type='int' primary-key='true' />
                <add name='store' />
                <add name='other' v=""jint(
   if(store === 'Other' && other === '') {
      otherMessage = 'other is required';
      false;
   } else {
      true;
   }
)""/>
            </fields>
            <calculated-fields>
               
            </calculated-fields>
        </add>
    </entities>

</add>";

            using (var outer = new ConfigurationContainer(new JintValidateModule()).CreateScope(xml, logger)) {
                var process = outer.Resolve <Process>();

                if (process.Errors().Any())
                {
                    foreach (var error in process.Errors())
                    {
                        System.Console.WriteLine(error);
                    }
                    return;
                }
                using (var inner = new Container(new JintValidateModule()).CreateScope(process, logger)) {
                    var controller = inner.Resolve <IProcessController>();
                    controller.Execute();
                    var rows = process.Entities.First().Rows;

                    Assert.AreEqual(true, rows[0]["otherValid"]);
                    Assert.AreEqual("", rows[0]["otherMessage"]);

                    Assert.AreEqual(true, rows[1]["otherValid"]);
                    Assert.AreEqual("", rows[1]["otherMessage"]);

                    Assert.AreEqual(false, rows[2]["otherValid"]);
                    Assert.AreEqual("other is required|", rows[2]["otherMessage"]);

                    Assert.AreEqual(true, rows[3]["otherValid"]);
                    Assert.AreEqual("", rows[3]["otherMessage"]);
                }
            }
        }