Ejemplo n.º 1
0
        public void TestSampleDataflow()
        {
            using (TestDb)
            {
                TableColumn keyCol = new TableColumn("Key", SqlDbType.Int, false, true, true);
                TableColumn col1   = new TableColumn("Col1", SqlDbType.NVarChar, 100, false);
                TableColumn col2   = new TableColumn("Col2", SqlDbType.NVarChar, 50, true);
                TableColumn col3   = new TableColumn("Col3", SqlDbType.Int, false);


                string destSchema  = "test";
                string destTable1  = "Staging1";
                string destObject1 = $"[{destSchema}].[{destTable1}]";
                new DropAndCreateTableTask(TestDb.getNewSqlConnection()).Execute(destSchema, destTable1, new List <TableColumn>()
                {
                    keyCol, col1, col2, col3
                });

                SqlDestination <string[]> destination1 = new SqlDestination <string[]>();
                destination1.ObjectName          = destObject1;
                destination1.FieldCount          = 4;
                destination1.ObjectMappingMethod = WriterAdapter_SampleDataflow.Fill;
                destination1.SqlConnection       = TestDb.getNewSqlConnection();

                string destTable2  = "Staging2";
                string destObject2 = $"[{destSchema}].[{destTable2}]";
                new DropAndCreateTableTask(TestDb.getNewSqlConnection()).Execute(destSchema, destTable2, new List <TableColumn>()
                {
                    keyCol, col1, col2, col3
                });



                SqlDestination <string[]> destination2 = new SqlDestination <string[]>();
                destination2.ObjectName          = destObject2;
                destination2.FieldCount          = 4;
                destination2.ObjectMappingMethod = WriterAdapter_SampleDataflow.Fill;
                destination2.SqlConnection       = TestDb.getNewSqlConnection();

                CSVSource <string[]> CSVSource =
                    new CSVSource <string[]>("DataFlow/InputData.csv");

                Graph g = new Graph();

                g.GetVertex(0, CSVSource);
                g.GetVertex(1, new RowTransformation <string[]>(RowTransformation1));
                g.GetVertex(11, new RowTransformation <string[]>(RowTransformation2));
                g.GetVertex(10, new BroadCast <string[]>(CloneTransformation1));
                g.GetVertex(12, new RowTransformationMany <string[]>(RowTransformationMany));
                g.GetVertex(20, new RowTransformation <string[]>(RowTransformation3));
                g.GetVertex(100, destination1);
                g.GetVertex(110, destination2);

                Edge e1 = g.AddEdge(0, 1);  // connect 0 to 1
                Edge e2 = g.AddEdge(1, 10); // connect 1 to 10
                Edge e3 = g.AddEdge(10, 20);
                Edge e4 = g.AddEdge(20, 100);
                Edge e5 = g.AddEdge(10, 11);
                Edge e6 = g.AddEdge(11, 12);
                Edge e7 = g.AddEdge(12, 110);


                DataFlowTask <string[]> .Execute("Test dataflow task", 1000, 1, g);

                e2.cost = counter_RowTransformation1;
                e6.cost = counter_RowTransformation2;
                e4.cost = counter_RowTransformation3;

                e7.cost = counter_RowTransformationMany;

                //TestHelper.VisualizeGraph(g);

                Assert.AreEqual(4, new ExecuteSQLTask(TestDb.getNewSqlConnection()).ExecuteScalar(string.Format("select count(*) from {0}", destObject1)));
                Assert.AreEqual(8, new ExecuteSQLTask(TestDb.getNewSqlConnection()).ExecuteScalar(string.Format("select count(*) from {0}", destObject2)));
            }
        }