Example #1
0
        public void SourceMoreColumnsThanDestination(IConnectionManager connection)
        {
            //Arrange
            FourColumnsTableFixture source4Columns = new FourColumnsTableFixture(connection, "SourceDynamic4Cols");

            source4Columns.InsertTestData();
            TwoColumnsTableFixture dest2Columns = new TwoColumnsTableFixture(connection, "DestinationDynamic2Cols");

            //Act
            DBSource <ExpandoObject>      source = new DBSource <ExpandoObject>(connection, "SourceDynamic4Cols");
            DBDestination <ExpandoObject> dest   = new DBDestination <ExpandoObject>(connection, "DestinationDynamic2Cols");

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

            //Assert
            dest2Columns.AssertTestData();
        }
        public void UsingClassMapAndNoHeader()
        {
            //Arrange
            FourColumnsTableFixture       d4c  = new FourColumnsTableFixture("CSVDestination4ColumnsClassMap");
            DBDestination <MyExtendedRow> dest = new DBDestination <MyExtendedRow>(Connection, "CSVDestination4ColumnsClassMap");

            //Act
            CSVSource <MyExtendedRow> source = new CSVSource <MyExtendedRow>("res/CSVSource/FourColumnsInvalidHeader.csv");

            source.Configuration.RegisterClassMap <ExtendedClassMap>();
            source.Configuration.HasHeaderRecord  = false;
            source.Configuration.ShouldSkipRecord = ShouldSkipRecordDelegate;
            source.LinkTo(dest);
            source.Execute();
            dest.Wait();

            //Assert
            d4c.AssertTestData();
        }
Example #3
0
        public void BigData_CSV_DB(int numberOfRows)
        {
            Stopwatch       watch        = new Stopwatch();
            TableDefinition stagingTable = new TableDefinition("test.Staging", new List <TableColumn>()
            {
                new TableColumn("Col1", "nchar(1000)", allowNulls: false),
                new TableColumn("Col2", "nchar(1000)", allowNulls: false),
                new TableColumn("Col3", "nchar(1000)", allowNulls: false),
                new TableColumn("Col4", "nchar(1000)", allowNulls: false),
            });

            stagingTable.CreateTable();
            string        fileName = "src/DataFlow/BigData_CSV2DB.csv";
            BigDataHelper bigData  = new BigDataHelper()
            {
                FileName        = fileName,
                NumberOfRows    = numberOfRows,
                TableDefinition = stagingTable
            };

            watch.Start();
            LogTask.Info($"Create .csv file {fileName} with {numberOfRows} Rows");
            bigData.CreateBigDataCSV();
            LogTask.Info($"Needed {watch.Elapsed.TotalMinutes} to create .csv file");
            watch.Reset();

            CSVSource source = new CSVSource(fileName);
            DBDestination <string[]> dest = new DBDestination <string[]>(1000)
            {
                DestinationTableDefinition = stagingTable
            };

            source.LinkTo(dest);

            watch.Start();
            source.Execute();
            LogTask.Info($"Needed {watch.Elapsed.TotalMinutes} to read everything into memory (while constantly writing)");
            LogTask.Info($"Already {RowCountTask.Count("test.Staging", RowCountOptions.QuickQueryMode)} inserted into table");
            dest.Wait(); //TODO Wait should be part of source
            LogTask.Info($"Needed {watch.Elapsed.TotalMinutes} to write everything into database");

            Assert.AreEqual(numberOfRows, SqlTask.ExecuteScalar <int>("Check staging table", $"select count(*) from test.Staging"));
        }
Example #4
0
        public void TestTransferBetweenDBs(IConnectionManager sourceConnection, IConnectionManager destConnection)
        {
            //Arrange
            TwoColumnsTableFixture source2Columns = new TwoColumnsTableFixture(sourceConnection, "Source");

            source2Columns.InsertTestData();
            TwoColumnsTableFixture dest2Columns = new TwoColumnsTableFixture(destConnection, "Destination");

            //Act
            DBSource      source = new DBSource(sourceConnection, "Source");
            DBDestination dest   = new DBDestination(destConnection, "Destination");

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

            //Assert
            dest2Columns.AssertTestData();
        }
Example #5
0
        public void Sql_Tablename()
        {
            TableDefinition destinationTableDefinition = new TableDefinition("test.Destination", new List <TableColumn>()
            {
                new TableColumn("Col1", "nvarchar(100)", allowNulls: false),
                new TableColumn("Col2", "int", allowNulls: true)
            });

            destinationTableDefinition.CreateTable();

            DBSource <MySimpleRow> source = new DBSource <MySimpleRow>(
                $@"select * from (values ('Test1',1), ('Test2',2), ('Test',3)) AS MyTable(Col1,Col2)");
            DBDestination <MySimpleRow> dest = new DBDestination <MySimpleRow>("test.Destination");

            source.LinkTo(dest);
            source.Execute();
            dest.Wait();
            Assert.AreEqual(3, RowCountTask.Count("test.Destination"));
        }
Example #6
0
        public void SimpleFlow(IConnectionManager connection)
        {
            //Arrange
            TwoColumnsTableFixture source2Columns = new TwoColumnsTableFixture(connection, "DBSourceSimple");

            source2Columns.InsertTestData();
            TwoColumnsTableFixture dest2Columns = new TwoColumnsTableFixture(connection, "DBDestinationSimple");

            //Act
            DBSource <MySimpleRow>      source = new DBSource <MySimpleRow>(connection, "DBSourceSimple");
            DBDestination <MySimpleRow> dest   = new DBDestination <MySimpleRow>(connection, "DBDestinationSimple");

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

            //Assert
            dest2Columns.AssertTestData();
        }
Example #7
0
        public void CSVIntoAccess()
        {
            //Arrange
            TableDefinition testTable = RecreateAccessTestTable();

            //Act
            CSVSource source = new CSVSource("res/UseCases/AccessData.csv");
            DBDestination <string[]> dest = new DBDestination <string[]>(testTable, batchSize: 2)
            {
                ConnectionManager = AccessOdbcConnection
            };

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

            //Assert
            Assert.Equal(3, RowCountTask.Count(AccessOdbcConnection, testTable.Name));
        }
Example #8
0
        public void AccessIntoDB()
        {
            //Arrange
            TableDefinition testTable = RecreateAccessTestTable();

            InsertTestData();
            TwoColumnsTableFixture destTable = new TwoColumnsTableFixture(SqlConnection, "dbo.AccessTargetTable");

            //Act
            DBSource <Data>      source = new DBSource <Data>(AccessOdbcConnection, "TestTable");
            DBDestination <Data> dest   = new DBDestination <Data>(SqlConnection, "dbo.AccessTargetTable");

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

            //Assert
            destTable.AssertTestData();
        }
Example #9
0
        public void ReadAndWriteToAzure()
        {
            //Arrange
            TwoColumnsTableFixture source2Columns = new TwoColumnsTableFixture(AzureSqlConnection, "[source].[AzureSource]");

            source2Columns.InsertTestData();
            TwoColumnsTableFixture dest2Columns = new TwoColumnsTableFixture(AzureSqlConnection, "[dest].[AzureDestination]");

            //Act
            DBSource <MySimpleRow>      source = new DBSource <MySimpleRow>(AzureSqlConnection, "[source].[AzureSource]");
            DBDestination <MySimpleRow> dest   = new DBDestination <MySimpleRow>(AzureSqlConnection, "[dest].[AzureDestination]");

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

            //Assert
            dest2Columns.AssertTestData();
        }
Example #10
0
        public void DifferentColumnsInView(IConnectionManager connection)
        {
            //Arrange
            FourColumnsTableFixture s4c = new FourColumnsTableFixture(connection, "dbsource_extended");

            s4c.InsertTestData();
            CreateViewTask.CreateOrAlter(connection, "DBSourceViewExtended", $"SELECT {s4c.QB}Col2{s4c.QE}, {s4c.QB}Col4{s4c.QE} FROM dbsource_extended");
            FourColumnsTableFixture d4c = new FourColumnsTableFixture(connection, "DBDestinationExtended", 1);

            //Act
            DBSource <MyExtendedRow>      source = new DBSource <MyExtendedRow>(connection, "DBSourceViewExtended");
            DBDestination <MyExtendedRow> dest   = new DBDestination <MyExtendedRow>(connection, "DBDestinationExtended");

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

            //Assert
            d4c.AssertTestData();
        }
Example #11
0
        public void SimpleFlow(IConnectionManager connection)
        {
            //Arrange
            TwoColumnsTableFixture source2Columns = new TwoColumnsTableFixture(connection, "dbsource_simple");

            source2Columns.InsertTestData();
            CreateViewTask.CreateOrAlter(connection, "DBSourceView", "SELECT * FROM dbsource_simple");
            TwoColumnsTableFixture dest2Columns = new TwoColumnsTableFixture(connection, "DBDestinationSimple");

            //Act
            DBSource <MySimpleRow>      source = new DBSource <MySimpleRow>(connection, "DBSourceView");
            DBDestination <MySimpleRow> dest   = new DBDestination <MySimpleRow>(connection, "DBDestinationSimple");

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

            //Assert
            dest2Columns.AssertTestData();
        }
Example #12
0
        public void WithoutErrorLinking(IConnectionManager connection)
        {
            //Arrange
            CreateSourceTable(connection, "DBSourceNoErrorLinking");

            TwoColumnsTableFixture dest2Columns = new TwoColumnsTableFixture(connection, "DBDestinationNoErrorLinking");

            //Act
            DBSource <MySimpleRow>      source = new DBSource <MySimpleRow>(connection, "DBSourceNoErrorLinking");
            DBDestination <MySimpleRow> dest   = new DBDestination <MySimpleRow>(connection, "DBDestinationNoErrorLinking");

            source.LinkTo(dest);

            //Assert
            Assert.Throws <System.FormatException>(() =>
            {
                source.Execute();
                dest.Wait();
            });
        }
        public void CustomSourceWithWebService()
        {
            //Arrange
            SqlTask.ExecuteNonQuery(Connection, "Create test table",
                                    @"CREATE TABLE dbo.WebServcieDestination 
                ( Id INT NOT NULL, UserId INT NOT NULL, Title NVARCHAR(100) NOT NULL, Completed BIT NOT NULL )"
                                    );
            DBDestination <Todo> dest     = new DBDestination <Todo>(Connection, "dbo.WebServcieDestination");
            WebserviceReader     wsreader = new WebserviceReader();

            //Act
            CustomSource <Todo> source = new CustomSource <Todo>(wsreader.ReadTodo, wsreader.EndOfData);

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

            //Assert
            Assert.Equal(5, RowCountTask.Count(Connection, "dbo.WebServcieDestination"));
        }
        public void WithAdditionalNotNullCol(IConnectionManager connection)
        {
            //Arrange
            TwoColumnsTableFixture s2c = new TwoColumnsTableFixture(connection, "source_additionalnotnullcol");

            s2c.InsertTestData();
            SqlTask.ExecuteNonQuery(connection, "Create destination table", @"CREATE TABLE destination_additionalnotnullcol
                (col1 VARCHAR(100) NULL, col2 VARCHAR(100) NULL, col3 VARCHAR(100) NOT NULL)");

            //Act
            DBSource      source = new DBSource(connection, "source_additionalnotnullcol");
            DBDestination dest   = new DBDestination(connection, "destination_additionalnotnullcol");

            source.LinkTo(dest);
            Assert.Throws <AggregateException>(() =>
            {
                source.Execute();
                dest.Wait();
            });
        }
Example #15
0
        public void DB_BlockTrans_DB()
        {
            TableDefinition sourceTableDefinition      = CreateSourceTable("test.Source");
            TableDefinition destinationTableDefinition = CreateDestinationTable("test.Destination");

            DBSource <MySimpleRow>      source = new DBSource <MySimpleRow>(sourceTableDefinition);
            DBDestination <MySimpleRow> dest   = new DBDestination <MySimpleRow>(destinationTableDefinition);
            Comparison <MySimpleRow>    comp   = new Comparison <MySimpleRow>(
                (x, y) => y.Col2 - x.Col2
                );
            Sort <MySimpleRow> block = new Sort <MySimpleRow>(comp);

            source.LinkTo(block);
            block.LinkTo(dest);
            source.Execute();
            dest.Wait();
            Assert.AreEqual(1, RowCountTask.Count("test.Destination", "[Key] = 1 and Col2 = 3"));
            Assert.AreEqual(1, RowCountTask.Count("test.Destination", "[Key] = 2 and Col2 = 2"));
            Assert.AreEqual(1, RowCountTask.Count("test.Destination", "[Key] = 3 and Col2 = 1"));
        }
Example #16
0
        public void SimpleLookupFromDB(IConnectionManager connection)
        {
            //Arrange
            TwoColumnsTableFixture source2Columns = new TwoColumnsTableFixture(connection, "Source");

            source2Columns.InsertTestData();
            FourColumnsTableFixture dest4Columns   = new FourColumnsTableFixture(connection, "Destination");
            FourColumnsTableFixture lookup4Columns = new FourColumnsTableFixture(connection, "Lookup");

            lookup4Columns.InsertTestData();

            DBSource <MyInputDataRow> source       = new DBSource <MyInputDataRow>(connection, "Source");
            DBSource <MyLookupRow>    lookupSource = new DBSource <MyLookupRow>(connection, "Lookup");

            //Act
            List <MyLookupRow> LookupTableData = new List <MyLookupRow>();
            Lookup <MyInputDataRow, MyOutputDataRow, MyLookupRow> lookup = new Lookup <MyInputDataRow, MyOutputDataRow, MyLookupRow>(
                row =>
            {
                MyOutputDataRow output = new MyOutputDataRow()
                {
                    Col1 = row.Col1,
                    Col2 = row.Col2,
                    Col3 = LookupTableData.Where(ld => ld.Key == row.Col1).Select(ld => ld.LookupValue1).FirstOrDefault(),
                    Col4 = LookupTableData.Where(ld => ld.Key == row.Col1).Select(ld => ld.LookupValue2).FirstOrDefault(),
                };
                return(output);
            }
                , lookupSource
                , LookupTableData
                );
            DBDestination <MyOutputDataRow> dest = new DBDestination <MyOutputDataRow>(connection, "Destination");

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

            //Assert
            dest4Columns.AssertTestData();
        }
Example #17
0
        public void DBSourceWithStringArray()
        {
            SqlTask.ExecuteNonQuery("Create source table", @"CREATE TABLE test.Source
                (Col1 nvarchar(100) null, Col2 int null)");
            SqlTask.ExecuteNonQuery("Insert demo data", "insert into test.Source values('Test1',1)");
            SqlTask.ExecuteNonQuery("Insert demo data", "insert into test.Source values('Test2',2)");
            SqlTask.ExecuteNonQuery("Insert demo data", "insert into test.Source values('Test3',3)");
            SqlTask.ExecuteNonQuery("Create destination table", @"CREATE TABLE test.Destination
                (Col1 nvarchar(30) null, Col2 bigint null)");

            DBSource      source = new DBSource("test.Source");
            DBDestination dest   = new DBDestination("test.Destination");

            source.LinkTo(dest);
            source.Execute();
            dest.Wait();
            Assert.AreEqual(3, RowCountTask.Count("test.Destination"));
            Assert.AreEqual(1, RowCountTask.Count("test.Destination", "Col1 = 'Test1' AND Col2=1"));
            Assert.AreEqual(1, RowCountTask.Count("test.Destination", "Col1 = 'Test2' AND Col2=2"));
            Assert.AreEqual(1, RowCountTask.Count("test.Destination", "Col1 = 'Test3' AND Col2=3"));
        }
Example #18
0
        public void DBMergeWithDeltaDestination()
        {
            CreateSourceTable();
            CreateDestinationTable();

            SqlTask.ExecuteNonQuery("Create delta table", @"CREATE TABLE test.Delta
                (ColKey int not null, ColValue nvarchar(30) null,
                    ChangeDate datetime null, ChangeAction char(1) not null)");


            DBSource <MySimpleRow>      source = new DBSource <MySimpleRow>("test.Source");
            DBMerge <MySimpleRow>       merge  = new DBMerge <MySimpleRow>("test.Destination");
            DBDestination <MySimpleRow> dest   = new DBDestination <MySimpleRow>("test.Delta");

            source.LinkTo(merge);
            merge.LinkTo(dest);
            source.Execute();
            merge.Wait();
            dest.Wait();
            //dest.Wait();
        }
        public void DataIsFromList()
        {
            //Arrange
            TwoColumnsTableFixture dest2Columns = new TwoColumnsTableFixture("MemoryDestinationNonGeneric");
            MemorySource           source       = new MemorySource();
            DBDestination          dest         = new DBDestination(SqlConnection, "MemoryDestinationNonGeneric");

            //Act
            source.Data = new List <string[]>()
            {
                new string[] { "1", "Test1" },
                new string[] { "2", "Test2" },
                new string[] { "3", "Test3" },
            };
            source.LinkTo(dest);
            source.Execute();
            dest.Wait();

            //Assert
            dest2Columns.AssertTestData();
        }
Example #20
0
        private TimeSpan GetETLBoxTime <T>(int numberOfRows, CSVSource <T> source, DBDestination <T> dest)
        {
            source.LinkTo(dest);
            var timeElapsedETLBox = BigDataHelper.LogExecutionTime($"Copying Csv into DB (non generic) with {numberOfRows} rows of data using ETLBox",
                                                                   () =>
            {
                source.Execute();
                dest.Wait();
            }
                                                                   );

            if (typeof(T) == typeof(string[]))
            {
                output.WriteLine("Elapsed " + timeElapsedETLBox.TotalSeconds + " seconds for ETLBox (Non generic).");
            }
            else
            {
                output.WriteLine("Elapsed " + timeElapsedETLBox.TotalSeconds + " seconds for ETLBox (Generic).");
            }
            return(timeElapsedETLBox);
        }
Example #21
0
        public void DB_BlockTrans_DB()
        {
            TableDefinition sourceTableDefinition      = CreateSourceTable("test.Source");
            TableDefinition destinationTableDefinition = CreateDestinationTable("test.Destination");

            DBSource <MySimpleRow>            source = new DBSource <MySimpleRow>(sourceTableDefinition);
            DBDestination <MySimpleRow>       dest   = new DBDestination <MySimpleRow>(destinationTableDefinition);
            BlockTransformation <MySimpleRow> block  = new BlockTransformation <MySimpleRow>(
                inputData => {
                return(inputData.Select(row => new MySimpleRow()
                {
                    Col1 = row.Col1, Col2 = 3
                }).ToList());
            });

            source.LinkTo(block);
            block.LinkTo(dest);
            source.Execute();
            dest.Wait();
            Assert.AreEqual(3, RowCountTask.Count("test.Destination", "Col2 in (3)"));
        }
Example #22
0
        public void WriteIntoTableWithPKAndFK(IConnectionManager connection)
        {
            //Arrange
            ReCreateOtherTable(connection, "FKReferenceTable");
            ReCreateTable(connection, "FKSourceTable");
            ReCreateTable(connection, "FKDestTable");
            InsertTestData(connection, "FKSourceTable");
            AddFKConstraint(connection, "FKDestTable", "FKReferenceTable");

            DBSource <MyRow> source = new DBSource <MyRow>(connection, "FKSourceTable");

            //Act
            DBDestination <MyRow> dest = new DBDestination <MyRow>(connection, "FKDestTable");

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

            //Assert
            Assert.Equal(3, RowCountTask.Count(connection, "FKDestTable").Value);
        }
Example #23
0
        public void DuplicateCheckWithBlockTrans()
        {
            //Arrange
            CSVSource <Poco> source = CreateDuplicateCSVSource("res/UseCases/DuplicateCheck.csv");
            List <int>       IDs    = new List <int>(); //at the end of the flow, this list will contain all IDs of your source

            //Act
            BlockTransformation <Poco> blockTrans = new BlockTransformation <Poco>(inputList =>
            {
                return(inputList.GroupBy(item => item.ID).Select(y => y.First()).ToList());
            });
            DBDestination <Poco> dest = CreateDestinationTable("dbo.DuplicateCheck");

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

            //Assert
            AssertDataWithoutDuplicates();
        }
Example #24
0
        public void DboTableName_DboTablename()
        {
            SqlTask.ExecuteNonQuery("Create source table", @"CREATE TABLE Source
                (Col1 nvarchar(100) null, Col2 int null)");
            SqlTask.ExecuteNonQuery("Insert demo data", "insert into Source values('Test1',1)");
            SqlTask.ExecuteNonQuery("Insert demo data", "insert into Source values('Test2',2)");
            SqlTask.ExecuteNonQuery("Insert demo data", "insert into Source values('Test3',3)");
            SqlTask.ExecuteNonQuery("Create destination table", @"CREATE TABLE Destination
                (Col1 nvarchar(30) null, Col2 bigint null)");

            DBSource <MySimpleRow>      source = new DBSource <MySimpleRow>("Source");
            DBDestination <MySimpleRow> dest   = new DBDestination <MySimpleRow>("Destination");

            source.LinkTo(dest);
            source.Execute();
            dest.Wait();
            Assert.AreEqual(3, RowCountTask.Count("Destination"));
            Assert.AreEqual(1, RowCountTask.Count("Destination", "Col1 = 'Test1' AND Col2=1"));
            Assert.AreEqual(1, RowCountTask.Count("Destination", "Col1 = 'Test2' AND Col2=2"));
            Assert.AreEqual(1, RowCountTask.Count("Destination", "Col1 = 'Test3' AND Col2=3"));
        }
Example #25
0
        public void DBDestinationWithColumnMapping()
        {
            SqlTask.ExecuteNonQuery("Create destination table", @"CREATE TABLE test.Destination
                (ID int not null identity (1,1) primary key,
                 Col1 nvarchar(30) null, Col2 nvarchar(30) null)");

            int index = 1;
            CustomSource <ColumnMapRow> source = new CustomSource <ColumnMapRow>(() => {
                return(new ColumnMapRow()
                {
                    Col1 = "Test" + index++,
                    B = "Test2",
                });
            }, () => index > 3);
            DBDestination <ColumnMapRow> dest = new DBDestination <ColumnMapRow>("test.Destination");

            source.LinkTo(dest);
            source.Execute();
            dest.Wait();
            Assert.AreEqual(3, RowCountTask.Count("test.Destination", "Col2 = 'Test2'"));
        }
        public void TwoMemSourcesIntoDB(IConnectionManager connection)
        {
            //Arrange
            MemorySource <MySimpleRow> source1 = new MemorySource <MySimpleRow>();
            MemorySource <MySimpleRow> source2 = new MemorySource <MySimpleRow>();

            //Act
            source1.Data = new List <MySimpleRow>()
            {
                new MySimpleRow()
                {
                    Col1 = 1, Col2 = "Test1"
                },
                new MySimpleRow()
                {
                    Col1 = 2, Col2 = "Test2"
                },
            };
            source2.Data = new List <MySimpleRow>()
            {
                new MySimpleRow()
                {
                    Col1 = 3, Col2 = "Test3"
                }
            };
            TwoColumnsTableFixture dest2Columns = new TwoColumnsTableFixture(connection, "DBMultipleDestination");

            //Act
            DBDestination <MySimpleRow> dest = new DBDestination <MySimpleRow>(connection, "DBMultipleDestination");

            source1.LinkTo(dest);
            source2.LinkTo(dest);
            source2.Execute();
            source1.Execute();

            dest.Wait();

            //Assert
            dest2Columns.AssertTestData();
        }
        public void CSV_DB_WithOdbcConnection()
        {
            ControlFlow.CurrentDbConnection = new OdbcConnectionManager(new OdbcConnectionString(OdbcConnectionStringParameter));

            CreateSchemaTask.Create("test");
            TableDefinition stagingTable = new TableDefinition("test.Staging", new List <TableColumn>()
            {
                new TableColumn("ID", "int", allowNulls: false, isPrimaryKey: true, isIdentity: true),
                new TableColumn("Col1", "bit", allowNulls: true),
                new TableColumn("Col2", "decimal(10,5)", allowNulls: true),
                new TableColumn("Col3", "tinyint", allowNulls: true),
                new TableColumn("Col4", "int", allowNulls: true),
                new TableColumn("Col5", "uniqueidentifier", allowNulls: true),
                new TableColumn("Col6", "nvarchar(100)", allowNulls: true)
            });

            stagingTable.CreateTable();
            CSVSource source = new CSVSource("src/ConnectionManager/DatatypeCSV.csv");
            RowTransformation <string[], string[]> trans = new RowTransformation <string[], string[]>("Set empty values to null",
                                                                                                      row => {
                for (int i = 0; i < row.Length; i++)
                {
                    if (row[i] == String.Empty)
                    {
                        row[i] = null;
                    }
                }
                return(row);
            });
            DBDestination <string[]> dest = new DBDestination <string[]>(stagingTable, 2);

            source.LinkTo(trans);
            trans.LinkTo(dest);

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


            Assert.AreEqual(3, RowCountTask.Count(stagingTable.Name));
        }
Example #28
0
        public void SqlWithSelectStar(IConnectionManager connection)
        {
            //Arrange
            TwoColumnsTableFixture s2c = new TwoColumnsTableFixture(connection, "SourceSelectStar");

            s2c.InsertTestData();
            TwoColumnsTableFixture d2c = new TwoColumnsTableFixture(connection, "DestinationSelectStar");

            //Act
            DBSource <MySimpleRow> source = new DBSource <MySimpleRow>()
            {
                Sql = $@"SELECT * FROM {s2c.QB}SourceSelectStar{s2c.QE}",
                ConnectionManager = connection
            };
            DBDestination <MySimpleRow> dest = new DBDestination <MySimpleRow>(connection, "DestinationSelectStar");

            source.LinkTo(dest);
            source.Execute();
            dest.Wait();
            d2c.AssertTestData();
            //Assert
        }
        public void WithObjectErrorLinking()
        {
            //Arrange
            TwoColumnsTableFixture          dest2Columns = new TwoColumnsTableFixture("ExcelSourceErrorLinking");
            DBDestination <MySimpleRow>     dest         = new DBDestination <MySimpleRow>(SqlConnection, "ExcelSourceErrorLinking");
            MemoryDestination <ETLBoxError> errorDest    = new MemoryDestination <ETLBoxError>();

            //Act
            ExcelSource <MySimpleRow> source = new ExcelSource <MySimpleRow>("res/Excel/TwoColumnErrorLinking.xlsx");

            source.LinkTo(dest);
            source.LinkErrorTo(errorDest);
            source.Execute();
            dest.Wait();
            errorDest.Wait();

            //Assert
            dest2Columns.AssertTestData();
            Assert.Collection <ETLBoxError>(errorDest.Data,
                                            d => Assert.True(!string.IsNullOrEmpty(d.RecordAsJson) && !string.IsNullOrEmpty(d.ErrorText))
                                            );
        }
Example #30
0
        public void CSVGeneric_DB()
        {
            TableDefinition stagingTable = new TableDefinition("test.Staging", new List <TableColumn>()
            {
                new TableColumn("Col1", "nvarchar(100)", allowNulls: false),
                new TableColumn("Col2", "int", allowNulls: true)
            });

            stagingTable.CreateTable();
            CSVSource <CSVData>     source = new CSVSource <CSVData>("src/DataFlow/Simple_CSV2DB.csv");
            DBDestination <CSVData> dest   = new DBDestination <CSVData>()
            {
                DestinationTableDefinition = stagingTable
            };

            source.LinkTo(dest);

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

            Assert.AreEqual(3, RowCountTask.Count("test.Staging", "Col1 Like '%ValueRow%' and Col2 <> 1"));
        }