Ejemplo n.º 1
0
        public void SimpleLookupWithDynamicObject(IConnectionManager connection)
        {
            //Arrange
            TwoColumnsTableFixture source2Columns = new TwoColumnsTableFixture(connection, "SourceLookupDynamicObject");

            source2Columns.InsertTestData();
            FourColumnsTableFixture dest4Columns = new FourColumnsTableFixture(connection, "DestinationLookupDynamicObject", -1);


            DbSource <ExpandoObject>      source = new DbSource <ExpandoObject>(connection, "SourceLookupDynamicObject");
            DbDestination <ExpandoObject> dest   = new DbDestination <ExpandoObject>(connection, "DestinationLookupDynamicObject");

            //Act
            List <ExpandoObject> lookupList = new List <ExpandoObject>();

            CsvSource <ExpandoObject> lookupSource = new CsvSource <ExpandoObject>("res/Lookup/LookupSource.csv");

            var lookup = new ETLBox.DataFlow.LookupTransformation <ExpandoObject, ExpandoObject>(
                lookupSource,
                row =>
            {
                dynamic r = row as ExpandoObject;
                r.Col3    = lookupList
                            .Where(lkupRow => { dynamic lk = lkupRow as dynamic;  return(int.Parse(lk.Key) == r.Col1); })
                            .Select(lkupRow => { dynamic lk = lkupRow as dynamic;
                                                 return(lk.Column3 == string.Empty ? null : Int64.Parse(lk.Column3)); })
                            .FirstOrDefault();
                r.Col4 = lookupList
                         .Where(lkupRow => { dynamic lk = lkupRow as dynamic; return(int.Parse(lk.Key) == r.Col1); })
                         .Select(lkupRow => { dynamic lk = lkupRow as dynamic; return(double.Parse(lk.Column4)); })
                         .FirstOrDefault();
                return(row);
            },
                lookupList
                );

            source.LinkTo(lookup);
            lookup.LinkTo(dest);
            source.Execute();
            dest.Wait();

            //Assert
            dest4Columns.AssertTestData();
        }
Ejemplo n.º 2
0
        public void InputTypeSameAsOutput(IConnectionManager connection)
        {
            //Arrange
            FourColumnsTableFixture source4Columns = new FourColumnsTableFixture(connection, "SourceLookupSameType");

            source4Columns.InsertTestData();
            FourColumnsTableFixture dest4Columns   = new FourColumnsTableFixture(connection, "DestinationLookupSameType");
            FourColumnsTableFixture lookup4Columns = new FourColumnsTableFixture(connection, "LookupSameType");

            lookup4Columns.InsertTestData();

            DbSource <MyDataRow>   source       = new DbSource <MyDataRow>("SourceLookupSameType", connection);
            DbSource <MyLookupRow> lookupSource = new DbSource <MyLookupRow>("LookupSameType", connection);

            var lookup = new ETLBox.DataFlow.LookupTransformation <MyDataRow, MyLookupRow>();

            lookup.TransformationFunc =
                row =>
            {
                row.Col1 = row.Col1;
                row.Col2 = row.Col2;
                row.Col3 = lookup.LookupData.Where(ld => ld.Key == row.Col1).Select(ld => ld.LookupValue1).FirstOrDefault();
                row.Col4 = lookup.LookupData.Where(ld => ld.Key == row.Col1).Select(ld => ld.LookupValue2).FirstOrDefault();
                return(row);
            };
            lookup.Source = lookupSource;
            DbDestination <MyDataRow> dest = new DbDestination <MyDataRow>("DestinationLookupSameType", connection);

            source.LinkTo(lookup);
            lookup.LinkTo(dest);
            source.Execute();
            dest.Wait();

            //Assert
            dest4Columns.AssertTestData();
        }