示例#1
0
        public void TryConvert()
        {
            var xml = @"
    <add name='TestProcess'>
      <entities>
        <add name='TestData' >
          <rows>
            <add OwensDate='02152018040000' />
          </rows>
          <fields>
            <add name='OwensDate' type='datetime' t='convert(date,MMddyyyyHHmmss)' />
          </fields>
        </add>
      </entities>
    </add>
            ".Replace('\'', '"');

            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml, LogLevel.Debug);

            controller.Execute();

            var row = composer.Process.Entities.First().Rows.First();

            Assert.AreEqual(new DateTime(2018, 2, 15, 4, 0, 0), row["OwensDate"]);
        }
        public void TryIt()
        {
            const string xml = @"
    <add name='TestProcess'>
      <entities>
        <add name='TestData'>
          <rows>
            <add Field1='11' Field2='12' Field3='13' />
            <add Field1='xx' Field2='' Field3='100.8' />
          </rows>
          <fields>
            <add name='Field1' v='contains(1)' message-field='Message' />
            <add name='Field2' v='required().is(int)' message-field='Message' />
            <add name='Field3' v='isnumeric().matches(^[0-9/.]{5}$)' message-field='Message' help='Field3 must be a 5 digit number (including decimal pt.)' />
          </fields>
          <calculated-fields>
            <add name='Message' length='1000' default='' />
          </calculated-fields>
        </add>
      </entities>
    </add>";

            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml);

            var output  = controller.Read().ToArray();
            var process = composer.Process;

            var message = process.Entities.First().CalculatedFields.First(cf => cf.Name == "Message");
            var valid   = process.Entities.First().CalculatedFields.First(cf => cf.Name == "TestDataValid");

            Assert.IsFalse((bool)output[0][valid]);
            Assert.AreEqual("Field3 must be a 5 digit number (including decimal pt.)", output[0][message].ToString().Replace("|", " ").TrimEnd());
            Assert.AreEqual("Field1 must contain 1. Field2 is required. Field2's value is incompatable with the int data type.", output[1][message].ToString().Replace("|", " ").TrimEnd());
        }
示例#3
0
        public void Match()
        {
            const string xml = @"
    <add name='TestProcess'>
      <entities>
        <add name='TestData' pipeline='linq'>
          <rows>
            <add Field1='Local/3114@tolocalext-fc5d,1' />
            <add Field1='SIP/Generic-Vitel_Outbound-0002b45a' />
          </rows>
          <fields>
            <add name='Field1' />
          </fields>
          <calculated-fields>
            <add name='MatchField1' t='copy(Field1).match(3[0-9]{3}(?=@))' default='None' />
            <add name='MatchAnyField' t='copy(Field1,Field2).match(3[0-9]{3}(?=@))' default='None' />
          </calculated-fields>
        </add>
      </entities>
    </add>";

            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml);
            var output     = controller.Read().ToArray();

            var cf = composer.Process.Entities.First().CalculatedFields.ToArray();

            Assert.AreEqual("3114", output[0][cf[0]]);
            Assert.AreEqual("3114", output[0][cf[1]]);
            Assert.AreEqual("None", output[1][cf[0]]);
            Assert.AreEqual("None", output[1][cf[1]]);
        }
示例#4
0
        public void JavascriptTransformAdd()
        {
            const string xml = @"
<add name='TestProcess'>
    <entities>
        <add name='TestData'>
            <rows>
                <add Field1='1' Field2='2' Field3='3' />
            </rows>
            <fields>
                <add name='Field1' />
                <add name='Field2' />
                <add name='Field3' />
            </fields>
            <calculated-fields>
                <add name='Format' engine='jint' t='copy(Field1,Field2,Field3).js(Field1+Field2+Field3)' />
            </calculated-fields>
        </add>
    </entities>
</add>";


            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml);

            var output = controller.Read().ToArray();

            Assert.AreEqual("123", output[0][composer.Process.Entities.First().CalculatedFields.First()]);
        }
示例#5
0
        public void VelocityTransformAdd()
        {
            const string xml = @"
<add name='TestProcess'>
    <entities>
        <add name='TestData'>
            <rows>
                <add Field1='1' Field2='2' Field3='3' />
            </rows>
            <fields>
                <add name='Field1' />
                <add name='Field2' />
                <add name='Field3' />
            </fields>
            <calculated-fields>
                <add name='Add' t='copy(Field1,Field2,Field3).velocity(#set($x = $Field1)$x$Field2$Field3)' />
            </calculated-fields>
        </add>
    </entities>
</add>";

            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml);

            var output = controller.Read().ToArray();

            Assert.AreEqual("123", output[0][composer.Process.Entities.First().CalculatedFields.First()]);
        }
示例#6
0
        public void RazorTransformAdd()
        {
            const string xml = @"
<add name='TestProcess'>
    <entities>
        <add name='TestData'>
            <rows>
                <add Field1='1' Field2='2' Field3='3' />
            </rows>
            <fields>
                <add name='Field1' />
                <add name='Field2' />
                <add name='Field3' />
            </fields>
            <calculated-fields>
                <add name='Add' t='copy(Field1,Field2,Field3).razor(@{var x = Model.Field1 + Model.Field2 + Model.Field3;}@x)' />
                <add name='Format' t='copy(Field1,Field2,Field3).razor(@{var x = string.Format(&quot;{0}-{1}-{2}&quot;\,Model.Field1\,Model.Field2\,Model.Field3);}@x)' />
            </calculated-fields>
        </add>
    </entities>
</add>";

            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml);

            var output = controller.Read().ToArray();

            Assert.AreEqual("123", output[0][composer.Process.Entities.First().CalculatedFields.First()]);
            Assert.AreEqual("1-2-3", output[0][composer.Process.Entities.First().CalculatedFields.Last()]);
        }
示例#7
0
        public void ExcludeTransform()
        {
            const string xml = @"
<add name='TestProcess'>
    <entities>
        <add name='TestData'>
            <rows>
                <add Field1='1' />
                <add Field1='2' />
            </rows>
            <fields>
                <add name='Field1' type='int' t='exclude(1)'/>
            </fields>
        </add>
    </entities>
</add>";


            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml);

            var output = controller.Read().ToArray();

            Assert.AreEqual(1, output.Length);
            Assert.AreEqual(2, output[0][composer.Process.Entities.First().Fields.First(f => !f.System)]);
        }
示例#8
0
        public void FormatTransformer()
        {
            const string xml = @"
    <add name='TestProcess'>
      <entities>
        <add name='TestData'>
          <rows>
            <add Field1='1' Field2='2' Field3='3' />
          </rows>
          <fields>
            <add name='Field1' />
            <add name='Field2' />
            <add name='Field3' type='double' />
          </fields>
          <calculated-fields>
            <add name='Format' t='copy(Field1,Field2,Field3).format({0}-{1}+{2} ).trim()' />
            <add name='BetterFormat' t='format({Field1}-{Field2}+{Field3} ).trim()' />
            <add name='FormatRepeats' t='copy(Field1,Field2,Field3).format({0}-{1}+{2}_{1})' />
            <add name='BetterFormatRepeats' t='format({Field1}-{Field2}+{Field3}_{Field2})' />
            <add name='WithFormat' t='format({Field1:#.0} and {Field3:000.0000})' />
          </calculated-fields>
        </add>
      </entities>
    </add>";

            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml);
            var output     = controller.Read().ToArray();

            Assert.AreEqual("1-2+3", output[0][composer.Process.Entities.First().CalculatedFields.First(f => f.Name == "Format")]);
            Assert.AreEqual("1-2+3", output[0][composer.Process.Entities.First().CalculatedFields.First(f => f.Name == "BetterFormat")]);
            Assert.AreEqual("1-2+3_2", output[0][composer.Process.Entities.First().CalculatedFields.First(f => f.Name == "FormatRepeats")]);
            Assert.AreEqual("1-2+3_2", output[0][composer.Process.Entities.First().CalculatedFields.First(f => f.Name == "BetterFormatRepeats")]);
            Assert.AreEqual("1 and 003.0000", output[0][composer.Process.Entities.First().CalculatedFields.First(f => f.Name == "WithFormat")]);
        }
示例#9
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 composer   = new CompositionRoot();
            var controller = composer.Compose(xml);

            controller.Execute();

            var process = composer.Process;
            var output  = process.Entities.First().Rows;

            Assert.AreEqual(true, output[0]["output"]);
            Assert.AreEqual(false, output[1]["output"]);
        }
示例#10
0
        public void TryDistinct()
        {
            const string xml = @"
    <add name='TestDistinct'>
      <entities>
        <add name='Dates'>
          <rows>
            <add Words='One Two Three One' />
            <add Words='111-222-3333 222-333-4444' />
          </rows>
          <fields>
            <add name='Words' />
          </fields>
          <calculated-fields>
            <add name='DistinctWords' t='copy(Words).distinct()' />
          </calculated-fields>
        </add>
      </entities>
    </add>";

            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml);

            controller.Execute();

            var process = composer.Process;
            var row1    = process.Entities.First().Rows[0];
            var row2    = process.Entities.First().Rows[1];

            Assert.AreEqual("One Two Three", row1["DistinctWords"]);
            Assert.AreEqual("111-222-3333 222-333-4444", row2["DistinctWords"]);
        }
示例#11
0
        public void FormatXmlTransform1()
        {
            const string xml = @"
<add name='TestProcess'>
    <entities>
        <add name='TestData'>
            <rows>
                <add xml='<stuff value=""1""><things><add item=""1""/><add item=""2""/></things></stuff>' />
            </rows>
            <fields>
                <add name='xml' length='128' />
            </fields>
            <calculated-fields>
                <add name='formatted' length='128' t='copy(xml).formatXml()' />
            </calculated-fields>
        </add>
    </entities>
</add>";

            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml);

            var output = controller.Read().ToArray();

            Assert.AreEqual(@"<stuff value=""1"">
  <things>
    <add item=""1"" />
    <add item=""2"" />
  </things>
</stuff>", output[0][composer.Process.Entities.First().CalculatedFields.First()]);
        }
示例#12
0
        public void XmlDecodeWorks()
        {
            const string xml = @"
    <add name='TestProcess'>
      <entities>
        <add name='TestData' pipeline='linq'>
          <rows>
            <add Field1='stranger &amp; things in the upside down' />
          </rows>
          <fields>
            <add name='Field1' />
          </fields>
          <calculated-fields>
            <add name='t1' t='copy(Field1).xmlDecode()' />
          </calculated-fields>
        </add>
      </entities>
    </add>";

            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml);
            var output     = controller.Read().ToArray();

            var cf = composer.Process.Entities.First().CalculatedFields.ToArray();

            Assert.AreEqual("stranger & things in the upside down", output[0][cf[0]]);
        }
        public void ItWorks()
        {
            const string xml = @"
    <add name='Test' read-only='true'>
      <entities>
        <add name='Data'>
          <rows>
            <add Date='2017-01-01 9 AM' Number='1' />
            <add Date='2016-06-07 12:31:22' Number='2' />
          </rows>
          <fields>
            <add name='Date' type='datetime' />
            <add name='Number' type='short' />
          </fields>
        </add>
      </entities>
    </add>";

            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml);

            controller.Execute();

            var process = composer.Process;
            var row1    = process.Entities.First().Rows[0];

            //var row2 = process.Entities.First().Rows[1];

            Assert.AreEqual(new DateTime(2017, 1, 1, 9, 0, 0), row1["Date"]);
            Assert.AreEqual((short)1, row1["Number"]);
        }
示例#14
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 composer   = new CompositionRoot();
            var controller = composer.Compose(xml);
            var output     = controller.Read().ToArray();

            var cf = composer.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]]);
        }
示例#15
0
        public void CopyTransform1()
        {
            const string xml = @"
<add name='TestProcess'>
    <entities>
        <add name='TestData'>
            <rows>
                <add Field1='1' Field2='2' />
            </rows>
            <fields>
                <add name='Field1' type='int'/>
                <add name='Field2' type='int'/>
            </fields>
            <calculated-fields>
                <add name='Field3' type='int' t='copy(Field2)' />
            </calculated-fields>
        </add>
    </entities>
</add>";


            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml);

            var output = controller.Read().ToArray();

            Assert.AreEqual(2, output[0][composer.Process.Entities.First().CalculatedFields.First()]);
        }
示例#16
0
        public void RunDelta()
        {
            var composer   = new CompositionRoot();
            var controller = composer.Compose(Cfg, LogLevel.Info);

            controller.Execute();
        }
示例#17
0
        public void DatePart1()
        {
            const string 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='StartYear' type='int' t='copy(StartDate).datepart(year)' />
            <add name='EndYear' type='int' t='copy(EndDate).datepart(year)' />
            <add name='StartWeek' type='int' t='copy(StartDate).datepart(weekofyear)' />
            <add name='EndWeek' type='int' t='copy(EndDate).datepart(weekofyear)' />
          </calculated-fields>
        </add>
      </entities>
    </add>";

            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml);
            var output     = controller.Read().ToArray();

            var cf = composer.Process.Entities.First().CalculatedFields.ToArray();

            Assert.AreEqual(2016, output[0][cf[0]]);
            Assert.AreEqual(2016, output[0][cf[1]]);
            Assert.AreEqual(23, output[0][cf[2]]);
            Assert.AreEqual(32, output[0][cf[3]]);
        }
示例#18
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,Field2).equal()' />
          </calculated-fields>
        </add>
      </entities>
    </add>
            ".Replace('\'', '"');

            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml);

            var output  = controller.Read().ToArray();
            var process = composer.Process;

            Assert.AreEqual(false, output[0][process.Entities.First().CalculatedFields.First(cf => cf.Name == "AreEqual")]);
            Assert.AreEqual(true, output[1][process.Entities.First().CalculatedFields.First(cf => cf.Name == "AreEqual")]);
        }
示例#19
0
        public void Read1()
        {
            const string xml = @"
<add name='Directory' mode='default'>
    <connections>
        <add name='input' provider='directory' folder='c:\temp' />
        <add name='output' provider='console' />
    </connections>
    <entities>
        <add name='Files'>
            <fields>
                <add name='DirectoryName' length='256' />
                <add name='FullName' length='256' />
                <add name='LastWriteTimeUtc' type='datetime' />
            </fields>
        </add>
    </entities>
</add>";


            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml, LogLevel.Debug);
            var process    = composer.Process;

            controller.Execute();
            controller.Dispose();

            var entity = process.Entities.First();

            Assert.AreEqual(115, entity.Rows.Count, "Most people keep about 115 files in there.");
        }
示例#20
0
        public void AnyWorks()
        {
            const string xml = @"
    <add name='TestProcess'>
      <entities>
        <add name='TestData' pipeline='linq'>
          <rows>
            <add Field1='1' Field2='2' Field3='3' />
          </rows>
          <fields>
            <add name='Field1' />
            <add name='Field2' />
            <add name='Field3' />
          </fields>
          <calculated-fields>
            <add name='Has1' type='bool' t='copy(*).any(1)' />
            <add name='Has2' type='bool' t='copy(Field1,Field2,Field3).any(2)' />
            <add name='Has3' type='bool' t='copy(*).any(3)' />
            <add name='Has4' type='bool' t='copy(Field1,Field2,Field3).any(4)' />
          </calculated-fields>
        </add>
      </entities>
    </add>";

            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml);
            var output     = controller.Read().ToArray();

            var cf = composer.Process.Entities.First().CalculatedFields.ToArray();

            Assert.AreEqual(true, output[0][cf[0]]);
            Assert.AreEqual(true, output[0][cf[1]]);
            Assert.AreEqual(true, output[0][cf[2]]);
            Assert.AreEqual(false, output[0][cf[3]]);
        }
示例#21
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 composer   = new CompositionRoot();
            var controller = composer.Compose(xml);
            var output     = controller.Read().ToArray();

            var cf = composer.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]]);
        }
示例#22
0
        public void FromLengths()
        {
            const string xml = @"
    <add name='TestProcess'>
      <entities>
        <add name='TestData'>
          <rows>
            <add line='122333444455555666666' />
            <add line='111111222223333444556' />
          </rows>
          <fields>
            <add name='line'>
                <transforms>
                    <add method='fromlengths'>
                        <fields>
                            <add name='f1' length='1' />
                            <add name='f2' length='2' />
                            <add name='f3' length='3' type='int' />
                            <add name='f4' length='4' />
                            <add name='f5' length='5' />
                            <add name='f6' length='6' />
                        </fields>
                    </add>
                </transforms>
            </add>
          </fields>
        </add>
      </entities>
    </add>";

            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml);
            var output     = controller.Read().ToArray();

            var cf = composer.Process.Entities.First().CalculatedFields.ToArray();

            var first = output[0];

            Assert.AreEqual("1", first[cf[0]]);
            Assert.AreEqual("22", first[cf[1]]);
            Assert.AreEqual(333, first[cf[2]]);
            Assert.AreEqual("4444", first[cf[3]]);
            Assert.AreEqual("55555", first[cf[4]]);
            Assert.AreEqual("666666", first[cf[5]]);

            var second = output[1];

            Assert.AreEqual("1", second[cf[0]]);
            Assert.AreEqual("11", second[cf[1]]);
            Assert.AreEqual(111, second[cf[2]]);
            Assert.AreEqual("2222", second[cf[3]]);
            Assert.AreEqual("23333", second[cf[4]]);
            Assert.AreEqual("444556", second[cf[5]]);
        }
示例#23
0
        public void DoMath()
        {
            const string xml = @"
    <add name='TestProcess'>
      <entities>
        <add name='TestData' pipeline='linq'>
          <rows>
            <add Field1='10.6954' Field2='129.992' Field3='7' Field4='3' />
          </rows>
          <fields>
            <add name='Field1' type='double' />
            <add name='Field2' type='decimal' />
            <add name='Field3' type='int' />
            <add name='Field4' type='int' />
          </fields>
          <calculated-fields>
            <add name='Ceiling' type='double' t='copy(Field1).ceiling()' />
            <add name='Floor' type='double' t='copy(Field1).floor()' />
            <add name='Round' type='decimal' t='copy(Field2).round(1)' />
            <add name='Abs' type='decimal' t='copy(Field2).abs()' />
            <add name='Add' type='decimal' t='copy(Field1,Field2,Field3).add()' />
            <add name='AddInts' type='int' t='copy(Field3,Field4).add()' />
            <add name='RoundTo5' type='double' t='copy(Field1).roundTo(5)' />
            <add name='RoundTo3' type='double' t='copy(Field1).roundTo(3)' />
            <add name='RoundTo7' type='decimal' t='copy(Field2).roundTo(7)' />
            <add name='RoundUpTo5' type='double' t='copy(Field1).roundUpTo(5)' />
            <add name='RoundDownTo4' type='int' t='copy(Field3).roundDownTo(4)' />
          </calculated-fields>
        </add>
      </entities>
    </add>";

            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml);
            var output     = controller.Read().ToArray();

            var cf  = composer.Process.Entities.First().CalculatedFields.ToArray();
            var row = output.First();

            Assert.AreEqual(11d, row[cf[0]]);
            Assert.AreEqual(10d, row[cf[1]]);
            Assert.AreEqual((decimal)130.00, row[cf[2]]);
            Assert.AreEqual((decimal)129.992, row[cf[3]]);
            Assert.AreEqual(147.6874m, row[cf[4]]);

            Assert.AreEqual(10, row[cf[5]]);
            Assert.AreEqual(10d, row[cf[6]], "nearest 5 is 10");
            Assert.AreEqual(12d, row[cf[7]], "nearest 3 is 12");
            Assert.AreEqual(133m, row[cf[8]], "nearest 7 is 133");
            Assert.AreEqual(15d, row[cf[9]], "next 5 is 15");
            Assert.AreEqual(4, row[cf[10]], "previous 4 is 4");
        }
示例#24
0
        public void FileStuff()
        {
            const string xml = @"
    <add name='TestProcess'>
      <connections>
        <add name='input' provider='internal' file='c:\temp.txt' port='6' />
        <add name='other' provider='internal' file='\\server\projects\ETL\2016-04-24.txt' />
      </connections>
      <entities>
        <add name='TestData'>
          <rows>
            <add Field1='1' Field2='2' Field3='3' />
          </rows>
          <fields>
            <add name='Field1' />
            <add name='Field2' />
            <add name='Field3' />
          </fields>
          <calculated-fields>
            <add name='File' type='string' t='connection(input,File)' />
            <add name='Port' type='int' t='connection(input,Port)' />            
            <add name='FileName' length='128' t='connection(other,File).filename()' />
            <add name='FileNameNoExt' length='128' t='connection(other,File).filename(false)' />
            <add name='FileExt' length='128' t='connection(other,File).fileext()' />
            <add name='FilePath' length='128' t='connection(other,File).filepath()' />
          </calculated-fields>
        </add>
      </entities>
    </add>
            ";

            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml);
            var output     = controller.Read().ToArray();

            var f             = composer.Process.Entities.First().CalculatedFields;
            var file          = f.First(cf => cf.Name == "File");
            var port          = f.First(cf => cf.Name == "Port");
            var fileName      = f.First(cf => cf.Name == "FileName");
            var fileNameNoExt = f.First(cf => cf.Name == "FileNameNoExt");
            var fileExt       = f.First(cf => cf.Name == "FileExt");
            var filePath      = f.First(cf => cf.Name == "FilePath");

            Assert.AreEqual(@"c:\temp.txt", output[0][file]);
            Assert.AreEqual(6, output[0][port]);
            Assert.AreEqual(@"2016-04-24.txt", output[0][fileName]);
            Assert.AreEqual(@"2016-04-24", output[0][fileNameNoExt]);
            Assert.AreEqual(@".txt", output[0][fileExt]);
            Assert.AreEqual(@"\\server\projects\ETL\2016-04-24.txt", output[0][filePath]);
        }
示例#25
0
        public void ConditionalFormat()
        {
            const string xml = @"
<add name='Test Conditional Format'>
    <entities>
        <add name='People'>
            <rows>
                <add First='Dale' Last='Newman' Gender='Male' />
                <add First='Owen' Last='Watson' Gender='Male' />
                <add First='Jeremy' Last='Christ' Gender='Male' />
                <add First='Kelly' Last='Jones' Gender='Female' />
            </rows>
            <fields>
                <add name='First' />
                <add name='Last' />
                <add name='Gender' />
            </fields>
            <calculated-fields>
                <add name='FullName' default='None'>
                    <transforms>
                        <add method='format' 
                            run-field='Gender'
                            run-operator='Equal'
                            run-value='Male'
                            format='{0} {1}'>
                            <parameters>
                                <add field='First' />
                                <add field='Last' />
                            </parameters>
                        </add>
                    </transforms>
                </add>
            </calculated-fields>
        </add>
    </entities>
</add>";

            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml);

            var output = controller.Read().ToArray();
            var full   = composer.Process.Entities.First().CalculatedFields[0];

            Assert.AreEqual(4, output.Count());
            Assert.AreEqual("Dale Newman", output[0][full]);
            Assert.AreEqual("Owen Watson", output[1][full]);
            Assert.AreEqual("Jeremy Christ", output[2][full]);
            Assert.AreEqual("None", output[3][full]);
        }
示例#26
0
        public void Contains()
        {
            const string xml = @"
    <add name='TestProcess'>
      <maps>
        <add name='Map'>
            <items>
                <add from='true' to='It is True' />
                <add from='false' to='It is False' />
                <add from='*' to='It is Unknown' />
            </items>
        </add>
      </maps>
      <entities>
        <add name='TestData' pipeline='linq'>
          <rows>
            <add Tags='Tag1 Tag2' />
            <add Tags='Tag2 Tag3' />
          </rows>
          <fields>
            <add name='Tags' />
          </fields>
          <calculated-fields>
            <add name='IsTag1' type='bool' t='copy(Tags).contains(Tag1)' />
            <add name='IsTag2' type='bool' t='copy(Tags).contains(Tag2)' />
            <add name='IsTag3' type='bool' t='copy(Tags).contains(Tag3)' />
            <add name='IsTag3Map' t='copy(Tags).contains(Tag3).map(Map)' />
          </calculated-fields>
        </add>
      </entities>
    </add>";

            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml);
            var output     = controller.Read().ToArray();

            var cf = composer.Process.Entities.First().CalculatedFields.ToArray();

            Assert.AreEqual(true, output[0][cf[0]]);
            Assert.AreEqual(true, output[0][cf[1]]);
            Assert.AreEqual(false, output[0][cf[2]]);
            Assert.AreEqual("It is False", output[0][cf[3]]);

            Assert.AreEqual(false, output[1][cf[0]]);
            Assert.AreEqual(true, output[1][cf[1]]);
            Assert.AreEqual(true, output[1][cf[2]]);
            Assert.AreEqual("It is True", output[1][cf[3]]);
        }
示例#27
0
        public void CSharpTransformAdd()
        {
            // Problem is I am compiling code in advance,
            // but not remembering that there are actually two processes that run,
            // the entity processes,  and the calculated field process

            const string xml = @"
<add name='TestProcess' mode='default'>
    <entities>
        <add name='TestData'>
            <rows>
                <add Field1='1' Field2='2' Field3='3' />
                <add Field1='4' Field2='5' Field3='6' />
            </rows>
            <fields>
                <add name='Field1' />
                <add name='Field2' />
                <add name='Field3' />
            </fields>
            <calculated-fields>
                <add name='Add' t='copy(Field1,Field2,Field3).cs(Field1+Field2+Field3;)' />
                <add name='Format' t='copy(Field1,Field2,Field3).cs(string.Format(&quot;{0}-{1}-{2}&quot;,Field1,Field2,Field3);)' />
            </calculated-fields>
        </add>
    </entities>
</add>";


            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml, LogLevel.Debug);
            var process    = composer.Process;

            controller.Execute();
            controller.Dispose();

            var entity = process.Entities.First();

            var row1 = entity.Rows[0];
            var row2 = entity.Rows[1];

            Assert.AreEqual("123", row1["Add"]);
            Assert.AreEqual("1-2-3", row1["Format"]);

            Assert.AreEqual("456", row2["Add"]);
            Assert.AreEqual("4-5-6", row2["Format"]);
        }
示例#28
0
        public void FromRegexWorks()
        {
            const string xml = @"
    <add name='Test'>
      <entities>
        <add name='Test'>
          <rows>
            <add address='1ST AV 1011' />
            <add address='1ST AV 402 APT 1' />
            <add address='ABLE RD 101 LOT 3' />
          </rows>
          <fields>
            <add name='address' length='128'>
                <transforms>
                    <add method='fromregex' pattern='( \d+)'>
                        <fields>
                            <add name='number' />
                        </fields>
                    </add>
                </transforms>
            </add>
          </fields>
          <calculated-fields>
            <add name='numberspace' t='copy(number).trim().append( )' />
            <add name='flipped' t='copy(address).replace(number,).prepend(numberspace)' />
          </calculated-fields>
        </add>
      </entities>
    </add>";

            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml);
            var output     = controller.Read().ToArray();
            var flipped    = composer.Process.Entities.First().CalculatedFields.Last();

            Assert.AreEqual(3, output.Length);

            Assert.AreEqual("1011 1ST AV", output[0][flipped]);
            Assert.AreEqual("402 1ST AV APT 1", output[1][flipped]);
            Assert.AreEqual("101 ABLE RD LOT 3", output[2][flipped]);

            foreach (var row in output)
            {
                Console.WriteLine(row);
            }
        }
示例#29
0
        public void MapTransformAdd()
        {
            const string xml = @"
<add name='TestProcess'>

    <maps>
        <add name='Map'>
            <items>
                <add from='1' to='One' />
                <add from='2' to='Two' />
                <add from='3' parameter='Field3' />
            </items>
        </add>
    </maps>

    <entities>
        <add name='TestData'>
            <rows>
                <add Field1='1' Field3='^' />
                <add Field1='2' Field3='#' />
                <add Field1='3' Field3='$THREE$' />
                <add Field1='4' Field3='@' />
            </rows>
            <fields>
                <add name='Field1' />
                <add name='Field2' />
                <add name='Field3' />
            </fields>
            <calculated-fields>
                <add name='Map' t='copy(Field1).map(map)' default='None' />
            </calculated-fields>
        </add>
    </entities>

</add>";

            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml);
            var field      = composer.Process.Entities.First().CalculatedFields.First();
            var output     = controller.Read().ToArray();

            Assert.AreEqual("One", output[0][field]);
            Assert.AreEqual("Two", output[1][field]);
            Assert.AreEqual("$THREE$", output[2][field]);
            Assert.AreEqual("None", output[3][field]);
        }
示例#30
0
        public void SliceWorks()
        {
            const string xml = @"
    <add name='TestProcess'>
      <entities>
        <add name='TestData' pipeline='linq'>
          <rows>
            <add Field1='stranger things in the upside down' Field2='10.2' Field3='jobs.mineplex.com' />
          </rows>
          <fields>
            <add name='Field1' />
            <add name='Field2' type='double' />
            <add name='Field3' />
          </fields>
          <calculated-fields>
            <add name='t1' t='copy(Field1).slice(1:3, )' />
            <add name='t2' t='copy(Field2).slice(1,.)' />
            <add name='t3' t='copy(Field3).slice(0:1,.)' />
            <add name='t4' t='copy(Field1).slice(2, )' />
            <add name='t5' t='copy(Field3).slice(-2,.)' />
            <add name='t6' t='copy(Field1).slice(::2, )' />
            <add name='t7' t='copy(Field1).slice(3:0:-1, )' />
            <add name='t8' t='copy(Field2).slice(0:2)' />
          </calculated-fields>
        </add>
      </entities>
    </add>";

            var composer   = new CompositionRoot();
            var controller = composer.Compose(xml);
            var output     = controller.Read().ToArray();

            var cf = composer.Process.Entities.First().CalculatedFields.ToArray();

            Assert.AreEqual("things in", output[0][cf[0]]);
            Assert.AreEqual("2", output[0][cf[1]]);
            Assert.AreEqual("jobs", output[0][cf[2]]);
            Assert.AreEqual("in the upside down", output[0][cf[3]]);
            Assert.AreEqual("mineplex.com", output[0][cf[4]]);
            Assert.AreEqual("stranger in upside", output[0][cf[5]]);
            Assert.AreEqual("the in things", output[0][cf[6]]);
            Assert.AreEqual("10", output[0][cf[7]]);
        }