Пример #1
0
        public void IgnoreWithStringArray()
        {
            //Arrange
            MemorySource source = new MemorySource();

            source.Data = new List <string[]>()
            {
                null,
                new string[] { "1", "Test1" },
                null,
                new string[] { "2", "Test2" },
                new string[] { "3", "Test3" },
                null
            };

            //Act
            CSVDestination dest = new CSVDestination("./IgnoreNullValuesStringArray.csv");

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

            //Assert
            Assert.Equal(File.ReadAllText("./IgnoreNullValuesStringArray.csv"),
                         File.ReadAllText("res/CSVDestination/TwoColumnsNoHeader.csv"));
        }
        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"));
        }
Пример #3
0
        public void NoErrorHandling()
        {
            //Arrange
            MemorySource <MySimpleRow> source = new MemorySource <MySimpleRow>();

            source.Data = new List <MySimpleRow>()
            {
                new MySimpleRow()
                {
                    Col1 = "X"
                },
                new MySimpleRow()
                {
                    Col1 = "1"
                },
                new MySimpleRow()
                {
                    Col1 = null
                }
            };
            CSVDestination <MySimpleRow> dest = new CSVDestination <MySimpleRow>("ErrorFileNoError.csv");

            //Act
            //Assert
            Assert.ThrowsAny <Exception>(() =>
            {
                source.LinkTo(dest);
                source.Execute();
                dest.Wait();
            });
        }
Пример #4
0
        public void IgnoreWithObject()
        {
            //Arrange
            MemorySource <MySimpleRow> source = new MemorySource <MySimpleRow>();

            source.Data = new List <MySimpleRow>()
            {
                null,
                new MySimpleRow()
                {
                    Col1 = 1, Col2 = "Test1"
                },
                null,
                new MySimpleRow()
                {
                    Col1 = 2, Col2 = "Test2"
                },
                new MySimpleRow()
                {
                    Col1 = 3, Col2 = "Test3"
                },
                null
            };

            //Act
            CSVDestination <MySimpleRow> dest = new CSVDestination <MySimpleRow>("./IgnoreNullValues.csv");

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

            //Assert
            Assert.Equal(File.ReadAllText("./IgnoreNullValues.csv"),
                         File.ReadAllText("res/CSVDestination/TwoColumns.csv"));
        }
Пример #5
0
        public void RedirectSingleRecordWithObject()
        {
            //Arrange
            MemorySource <MySimpleRow> source = new MemorySource <MySimpleRow>();

            source.Data = new List <MySimpleRow>()
            {
                new MySimpleRow()
                {
                    Col1 = "X"
                },
                new MySimpleRow()
                {
                    Col1 = "1"
                },
                new MySimpleRow()
                {
                    Col1 = "2"
                },
                new MySimpleRow()
                {
                    Col1 = null
                },
                new MySimpleRow()
                {
                    Col1 = "3"
                },
            };
            CSVDestination <MySimpleRow>    dest      = new CSVDestination <MySimpleRow>("ErrorFile.csv");
            MemoryDestination <ETLBoxError> errorDest = new MemoryDestination <ETLBoxError>();

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

            //Assert
            Assert.Equal(File.ReadAllText("./ErrorFile.csv"),
                         File.ReadAllText("res/CSVDestination/TwoColumnsErrorLinking.csv"));
            Assert.Collection <ETLBoxError>(errorDest.Data,
                                            d => Assert.True(!string.IsNullOrEmpty(d.RecordAsJson) && !string.IsNullOrEmpty(d.ErrorText)),
                                            d => Assert.True(!string.IsNullOrEmpty(d.RecordAsJson) && !string.IsNullOrEmpty(d.ErrorText))
                                            );
        }
Пример #6
0
        public void SimpleFlowWithBatchWrite()
        {
            //Arrange
            TwoColumnsTableFixture s2C = new TwoColumnsTableFixture("CSVDestBatch");

            s2C.InsertTestDataSet3();
            DBSource <MySimpleRow> source = new DBSource <MySimpleRow>(SqlConnection, "CSVDestBatch");

            //Act
            CSVDestination <MySimpleRow> dest = new CSVDestination <MySimpleRow>("./ObjectWithBatchWrite.csv", 2);

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

            //Assert
            Assert.Equal(File.ReadAllText("./ObjectWithBatchWrite.csv"),
                         File.ReadAllText("res/CSVDestination/TwoColumnsSet3.csv"));
        }
        public void SimpleFlow()
        {
            //Arrange
            TwoColumnsTableFixture s2C = new TwoColumnsTableFixture("CSVDestDynamicObject");

            s2C.InsertTestDataSet3();
            DBSource <ExpandoObject> source = new DBSource <ExpandoObject>(SqlConnection, "CSVDestDynamicObject");

            //Act
            CSVDestination <ExpandoObject> dest = new CSVDestination <ExpandoObject>("./SimpleWithDynamicObject.csv");

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

            //Assert
            Assert.Equal(File.ReadAllText("./SimpleWithDynamicObject.csv"),
                         File.ReadAllText("res/CSVDestination/TwoColumnsSet3DynamicObject.csv"));
        }
Пример #8
0
        public void SimpleNonGeneric()
        {
            //Arrange
            TwoColumnsTableFixture s2C = new TwoColumnsTableFixture("CSVDestSimpleNonGeneric");

            s2C.InsertTestDataSet3();
            DBSource source = new DBSource(SqlConnection, "CSVDestSimpleNonGeneric");

            //Act
            CSVDestination dest = new CSVDestination("./SimpleNonGeneric.csv");

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

            //Assert
            //Assert
            Assert.Equal(File.ReadAllText("./SimpleNonGeneric.csv"),
                         File.ReadAllText("res/CSVDestination/TwoColumnsSet3NoHeader.csv"));
        }
Пример #9
0
        public void DisableHeader()
        {
            //Arrange
            TwoColumnsTableFixture s2c = new TwoColumnsTableFixture("CSVSourceNoHeader");

            s2c.InsertTestData();
            DBSource <MySimpleRow> source = new DBSource <MySimpleRow>(SqlConnection, "CSVSourceNoHeader");

            //Act
            CSVDestination <MySimpleRow> dest = new CSVDestination <MySimpleRow>("./ConfigurationNoHeader.csv");

            dest.Configuration.HasHeaderRecord = false;
            source.LinkTo(dest);
            source.Execute();
            dest.Wait();

            //Assert
            Assert.Equal(File.ReadAllText("./ConfigurationNoHeader.csv"),
                         File.ReadAllText("res/CSVDestination/TwoColumnsNoHeader.csv"));
        }
Пример #10
0
        public void WriteAsyncAndCheckLock(string filename, int noRecords)
        {
            //Arrange
            if (File.Exists(filename))
            {
                File.Delete(filename);
            }
            MemorySource source = new MemorySource();

            for (int i = 0; i < noRecords; i++)
            {
                source.Data.Add(new string[] { HashHelper.RandomString(100) });
            }
            CSVDestination dest            = new CSVDestination(filename);
            bool           onCompletionRun = false;

            //Act
            source.LinkTo(dest);
            Task sT = source.ExecuteAsync();
            Task dt = dest.Completion;

            while (!File.Exists(filename))
            {
                Task.Delay(10).Wait();
            }

            //Assert
            dest.OnCompletion = () =>
            {
                Assert.False(IsFileLocked(filename), "StreamWriter should be disposed and file unlocked");
                onCompletionRun = true;
            };

            Assert.True(IsFileLocked(filename), "Right after  start the file should still be locked.");
            dt.Wait();
            Assert.True(onCompletionRun, "OnCompletion action and assertion did run");
        }