Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
0
        public void ExecuteReaderMultiColumn(IConnectionManager connection)
        {
            //Arrange
            TwoColumnsTableFixture tc = new TwoColumnsTableFixture(connection, "MultiColumnRead");

            tc.InsertTestData();

            List <MySimpleRow> asIsResult = new List <MySimpleRow>();
            List <MySimpleRow> toBeResult = new List <MySimpleRow>()
            {
                new MySimpleRow(1, "Test1"),
                new MySimpleRow(2, "Test2"),
                new MySimpleRow(3, "Test3")
            };
            MySimpleRow CurColumn = new MySimpleRow();

            //Act
            SqlTask.ExecuteReader(connection,
                                  "Test execute reader",
                                  $"SELECT * FROM {tc.QB}MultiColumnRead{tc.QE}"
                                  , () => CurColumn = new MySimpleRow()
                                  , () => asIsResult.Add(CurColumn)
                                  , colA => CurColumn.Col1 = int.Parse(colA.ToString())
                                  , colB => CurColumn.Col2 = (string)colB
                                  );

            //Assert
            Assert.Equal(toBeResult, asIsResult);
        }
Ejemplo n.º 3
0
            public MySimpleRow ReadData()
            {
                var result = new MySimpleRow()
                {
                    Col1 = Data[_readIndex],
                    Col2 = _readIndex
                };

                _readIndex++;
                return(result);
            }
Ejemplo n.º 4
0
            public MySimpleRow ReadData()
            {
                var result = new MySimpleRow()
                {
                    Value1 = Data[_readIndex],
                    Value2 = _readIndex
                };

                _readIndex++;
                return(result);
            }
        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))
                                            );
        }
Ejemplo n.º 6
0
        public void SimpleAsyncFlow()
        {
            //Arrange
            TwoColumnsTableFixture dest2Columns = new TwoColumnsTableFixture("Destination4CustomSource");
            List <string>          Data         = new List <string>()
            {
                "Test1", "Test2", "Test3"
            };
            int _readIndex = 0;
            Func <MySimpleRow> ReadData = () =>
            {
                if (_readIndex == 0)
                {
                    Task.Delay(300).Wait();
                }
                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>(SqlConnection, "Destination4CustomSource");

            source.LinkTo(dest);
            Task sourceT = source.ExecuteAsync();
            Task destT   = dest.Completion;

            //Assert
            Assert.True(RowCountTask.Count(SqlConnection, "Destination4CustomSource") == 0);
            sourceT.Wait();
            destT.Wait();
            dest2Columns.AssertTestData();
        }
Ejemplo n.º 7
0
 public MySimpleRow TestTransformationFunc(MySimpleRow myRow)
 {
     myRow.Col2 += AddValue;
     return(myRow);
 }