コード例 #1
0
        public void SimpleFlow()
        {
            //Arrange
            TwoColumnsTableFixture dest2Columns = new TwoColumnsTableFixture("Destination4CustomSourceDynamic");
            List <string>          Data         = new List <string>()
            {
                "Test1", "Test2", "Test3"
            };
            int _readIndex = 0;
            Func <ExpandoObject> ReadData = () =>
            {
                dynamic result = new ExpandoObject();
                result.Col1 = (_readIndex + 1).ToString();
                result.Col2 = Data[_readIndex];
                _readIndex++;
                return(result);
            };

            Func <bool> EndOfData = () => _readIndex >= Data.Count;

            //Act
            CustomSource <ExpandoObject>  source = new CustomSource <ExpandoObject>(ReadData, EndOfData);
            DbDestination <ExpandoObject> dest   = new DbDestination <ExpandoObject>("Destination4CustomSourceDynamic", Connection);

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

            //Assert
            dest2Columns.AssertTestData();
        }
コード例 #2
0
        public void SimpleFlow()
        {
            //Arrange
            TwoColumnsTableFixture dest2Columns = new TwoColumnsTableFixture("Destination4CustomSource");
            List <string>          Data         = new List <string>()
            {
                "Test1", "Test2", "Test3"
            };
            int _readIndex = 0;
            Func <MySimpleRow> ReadData = () =>
            {
                var result = new MySimpleRow()
                {
                    Col1 = _readIndex + 1,
                    Col2 = Data[_readIndex]
                };
                _readIndex++;
                return(result);
            };

            Func <bool> EndOfData = () => _readIndex >= Data.Count;

            //Act
            CustomSource <MySimpleRow>  source = new CustomSource <MySimpleRow>(ReadData, EndOfData);
            DBDestination <MySimpleRow> dest   = new DBDestination <MySimpleRow>(Connection, "Destination4CustomSource");

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

            //Assert
            dest2Columns.AssertTestData();
        }
コード例 #3
0
        public void SerializingDateTime()
        {
            int rowCount = 0;
            //Arrange
            CustomSource <MySeriRow> source = new CustomSource <MySeriRow>(
                () =>
                new MySeriRow()
            {
                Col1 = 1,
                Col2 = new DateTime(2010, 02, 05)
            },
                () => rowCount++ == 1);


            //Act
            CSVDestination <MySeriRow> dest = new CSVDestination <MySeriRow>("./DateTimeSerialization.csv");

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

            //Assert
            Assert.Equal(File.ReadAllText("./DateTimeSerialization.csv"),
                         File.ReadAllText("res/CSVDestination/DateTimeSerialization.csv"));
        }
コード例 #4
0
        public void SimpleFlow()
        {
            //Arrange
            TwoColumnsTableFixture dest2Columns = new TwoColumnsTableFixture("Destination4CustomSourceNonGeneric");
            List <string>          Data         = new List <string>()
            {
                "Test1", "Test2", "Test3"
            };
            int             _readIndex = 0;
            Func <string[]> ReadData   = () =>
            {
                string[] result = new string[2];
                result[0] = (_readIndex + 1).ToString();
                result[1] = Data[_readIndex];
                _readIndex++;
                return(result);
            };

            Func <bool> EndOfData = () => _readIndex >= Data.Count;

            //Act
            CustomSource <string[]>  source = new CustomSource <string[]>(ReadData, EndOfData);
            DbDestination <string[]> dest   = new DbDestination <string[]>(Connection, "Destination4CustomSourceNonGeneric");

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

            //Assert
            dest2Columns.AssertTestData();
        }
コード例 #5
0
        public void CustSource_DB()
        {
            TableDefinition destinationTableDefinition = CreateDestinationTable("test.Destination");

            CustomRowReader             rowReaderClass = new CustomRowReader();
            CustomSource <MySimpleRow>  source         = new CustomSource <MySimpleRow>(rowReaderClass.ReadData, rowReaderClass.EndOfData);
            DBDestination <MySimpleRow> dest           = new DBDestination <MySimpleRow>(destinationTableDefinition);

            source.LinkTo(dest);
            source.Execute();
            dest.Wait();
            Assert.AreEqual(3, RowCountTask.Count("test.Destination"));
        }
コード例 #6
0
        public void CustSource_DB()
        {
            TableDefinition destinationTableDefinition = CreateDestinationTable("test.Destination");

            CustomRowReader             rowReaderClass = new CustomRowReader();
            CustomSource <MySimpleRow>  source         = new CustomSource <MySimpleRow>(rowReaderClass.ReadData, rowReaderClass.EndOfData);
            DBDestination <MySimpleRow> dest           = new DBDestination <MySimpleRow>(destinationTableDefinition);

            source.LinkTo(dest);
            source.Execute();
            dest.Wait();
            Assert.AreEqual(3, SqlTask.ExecuteScalar <int>("Check destination table", "select count(*) from test.Destination"));
        }
コード例 #7
0
        public void CustomSourceWithWebService()
        {
            SqlTask.ExecuteNonQuery("Create test table",
                                    @"CREATE TABLE dbo.ws_dest 
                ( Id INT NOT NULL, UserId INT NOT NULL, Title NVARCHAR(100) NOT NULL, Completed BIT NOT NULL )"
                                    );

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

            DBDestination <Todo> dest = new DBDestination <Todo>("dbo.ws_dest");

            source.LinkTo(dest);
            source.Execute();
            dest.Wait();
        }
コード例 #8
0
        public void SimpleFlow()
        {
            //Arrange
            TwoColumnsTableFixture dest2Columns = new TwoColumnsTableFixture("ErrorLinkingCustomSource");
            List <string>          Data         = new List <string>()
            {
                "Test1", "Test2", "Test3", "Test4"
            };
            int _readIndex = 0;
            Func <MySimpleRow> ReadData = () =>
            {
                var result = new MySimpleRow()
                {
                    Col1 = _readIndex + 1,
                    Col2 = Data[_readIndex]
                };
                _readIndex++;
                if (_readIndex == 4)
                {
                    throw new Exception("Error record!");
                }
                return(result);
            };

            Func <bool> EndOfData = () => _readIndex >= Data.Count;

            CustomSource <MySimpleRow>      source    = new CustomSource <MySimpleRow>(ReadData, EndOfData);
            DbDestination <MySimpleRow>     dest      = new DbDestination <MySimpleRow>(SqlConnection, "ErrorLinkingCustomSource");
            MemoryDestination <ETLBoxError> errorDest = new MemoryDestination <ETLBoxError>();

            //Act
            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))
                                            );
        }
コード例 #9
0
        public void CustomSourceWithWebService()
        {
            //Arrange
            SqlTask.ExecuteNonQuery(Connection, "Create test table",
                                    @"CREATE TABLE dbo.WebServiceDestination 
                ( Id INT NOT NULL, Title NVARCHAR(100) NOT NULL, Completed BIT NOT NULL )"
                                    );
            DbDestination <Todo> dest     = new DbDestination <Todo>(Connection, "dbo.WebServiceDestination");
            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.WebServiceDestination"));
        }
コード例 #10
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'"));
        }