public void ThrowExceptionWithoutHandling()
        {
            //Arrange
            TwoColumnsTableFixture source2Columns = new TwoColumnsTableFixture("RowMultiplicationSource");

            source2Columns.InsertTestData();

            DbSource <MySimpleRow>          source         = new DbSource <MySimpleRow>(SqlConnection, "RowMultiplicationSource");
            RowMultiplication <MySimpleRow> multiplication = new RowMultiplication <MySimpleRow>(
                row =>
            {
                List <MySimpleRow> result = new List <MySimpleRow>();
                result.Add(row);
                if (row.Col1 == 2)
                {
                    throw new Exception("Error in Flow!");
                }
                return(result);
            });
            MemoryDestination <MySimpleRow> dest = new MemoryDestination <MySimpleRow>();

            //Act & Assert
            source.LinkTo(multiplication);
            multiplication.LinkTo(dest);

            Assert.Throws <AggregateException>(() =>
            {
                source.Execute();
                dest.Wait();
            });
        }
예제 #2
0
        static void Main(string[] args)
        {
            var source = new CsvSource <InputData>("Accounts_Quartal1.csv");

            source.Configuration.Delimiter = ";";

            var trans = new RowMultiplication <InputData, PivotedOutput>();

            trans.MultiplicationFunc = row =>
            {
                List <PivotedOutput> result = new List <PivotedOutput>();
                result.Add(new PivotedOutput()
                {
                    Account      = row.Account,
                    Month        = nameof(InputData.January),
                    MonthlyValue = row.January
                });
                result.Add(new PivotedOutput()
                {
                    Account      = row.Account,
                    Month        = nameof(InputData.February),
                    MonthlyValue = row.February
                });
                result.Add(new PivotedOutput()
                {
                    Account      = row.Account,
                    Month        = nameof(InputData.March),
                    MonthlyValue = row.March
                });
                return(result);
            };
            var dest = new CsvDestination <PivotedOutput>("AccountNumbers_Pivoted.csv");

            dest.Configuration.HasHeaderRecord = false;

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

            Network.Execute(source);

            /* AccountNumbers_Pivoted.csv output:
             *  4711,January,10
             *  4711,February,11
             *  4711,March,12
             *  4712,January,20
             *  4712,February,21
             *  4712,March,22
             *  4713,January,30
             *  4713,February,31
             *  4713,March,32
             */
        }
        public void IgnoreWithObject()
        {
            //Arrange
            MemorySource <MySimpleRow> source = new MemorySource <MySimpleRow>();

            source.DataAsList = 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
            RowMultiplication <MySimpleRow> multiplication = new RowMultiplication <MySimpleRow>(
                row => new List <MySimpleRow>()
            {
                row, row
            }
                );
            MemoryDestination <MySimpleRow> dest = new MemoryDestination <MySimpleRow>();

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

            //Assert
            Assert.Collection(dest.Data,
                              d => Assert.True(d.Col1 == 1 && d.Col2 == "Test1"),
                              d => Assert.True(d.Col1 == 1 && d.Col2 == "Test1"),
                              d => Assert.True(d.Col1 == 2 && d.Col2 == "Test2"),
                              d => Assert.True(d.Col1 == 2 && d.Col2 == "Test2"),
                              d => Assert.True(d.Col1 == 3 && d.Col2 == "Test3"),
                              d => Assert.True(d.Col1 == 3 && d.Col2 == "Test3")
                              );
        }
예제 #4
0
        public void ReturningNewDynamicObject()
        {
            //Arrange
            TwoColumnsTableFixture source2Columns = new TwoColumnsTableFixture("RowMultiplicationSource");

            source2Columns.InsertTestData();

            DbSource          source         = new DbSource(SqlConnection, "RowMultiplicationSource");
            RowMultiplication multiplication = new RowMultiplication(
                row =>
            {
                List <ExpandoObject> result = new List <ExpandoObject>();
                dynamic r = row as ExpandoObject;
                for (int i = 0; i <= r.Col1; i++)
                {
                    dynamic newdynamic = new ExpandoObject();
                    newdynamic.Col3    = i * r.Col1;
                    result.Add(newdynamic);
                }
                return(result);
            });
            MemoryDestination dest = new MemoryDestination();

            //Act
            source.LinkTo(multiplication);
            multiplication.LinkTo(dest);
            source.Execute();
            dest.Wait();

            //Assert
            Assert.Collection(dest.Data,
                              d => { dynamic r = d as dynamic; Assert.True(r.Col3 == 0); },
                              d => { dynamic r = d as dynamic; Assert.True(r.Col3 == 1); },
                              d => { dynamic r = d as dynamic; Assert.True(r.Col3 == 0); },
                              d => { dynamic r = d as dynamic; Assert.True(r.Col3 == 2); },
                              d => { dynamic r = d as dynamic; Assert.True(r.Col3 == 4); },
                              d => { dynamic r = d as dynamic; Assert.True(r.Col3 == 0); },
                              d => { dynamic r = d as dynamic; Assert.True(r.Col3 == 3); },
                              d => { dynamic r = d as dynamic; Assert.True(r.Col3 == 6); },
                              d => { dynamic r = d as dynamic; Assert.True(r.Col3 == 9); }
                              );
        }
예제 #5
0
        public void DifferentOutputType()
        {
            //Arrange
            TwoColumnsTableFixture source2Columns = new TwoColumnsTableFixture("RowMultiplicationSource");

            source2Columns.InsertTestData();

            DbSource <MySimpleRow> source = new DbSource <MySimpleRow>(SqlConnection, "RowMultiplicationSource");
            RowMultiplication <MySimpleRow, MyOtherRow> multiplication = new RowMultiplication <MySimpleRow, MyOtherRow>(
                row =>
            {
                List <MyOtherRow> result = new List <MyOtherRow>();
                for (int i = 0; i <= row.Col1; i++)
                {
                    result.Add(new MyOtherRow()
                    {
                        Col3 = i * row.Col1,
                    });
                }
                return(result);
            });
            MemoryDestination <MyOtherRow> dest = new MemoryDestination <MyOtherRow>();

            //Act
            source.LinkTo(multiplication);
            multiplication.LinkTo(dest);
            source.Execute();
            dest.Wait();

            //Assert
            Assert.Collection(dest.Data,
                              d => Assert.True(d.Col3 == 0),
                              d => Assert.True(d.Col3 == 1),
                              d => Assert.True(d.Col3 == 0),
                              d => Assert.True(d.Col3 == 2),
                              d => Assert.True(d.Col3 == 4),
                              d => Assert.True(d.Col3 == 0),
                              d => Assert.True(d.Col3 == 3),
                              d => Assert.True(d.Col3 == 6),
                              d => Assert.True(d.Col3 == 9)
                              );
        }
예제 #6
0
        public void RandomDoubling()
        {
            //Arrange
            TwoColumnsTableFixture source2Columns = new TwoColumnsTableFixture("RowMultiplicationSource");

            source2Columns.InsertTestData();

            DbSource <string[]>          source         = new DbSource <string[]>(SqlConnection, "RowMultiplicationSource");
            RowMultiplication <string[]> multiplication = new RowMultiplication <string[]>(
                row =>
            {
                List <string[]> result = new List <string[]>();
                int id = int.Parse(row[0]);
                for (int i = 0; i < id; i++)
                {
                    result.Add(new string[]
                    {
                        (id + i).ToString(),
                        "Test" + (id + i)
                    });
                }
                return(result);
            });
            MemoryDestination <string[]> dest = new MemoryDestination <string[]>();

            //Act
            source.LinkTo(multiplication);
            multiplication.LinkTo(dest);
            source.Execute();
            dest.Wait();

            //Assert
            Assert.Collection(dest.Data,
                              d => Assert.True(d[0] == "1" && d[1] == "Test1"),
                              d => Assert.True(d[0] == "2" && d[1] == "Test2"),
                              d => Assert.True(d[0] == "3" && d[1] == "Test3"),
                              d => Assert.True(d[0] == "3" && d[1] == "Test3"),
                              d => Assert.True(d[0] == "4" && d[1] == "Test4"),
                              d => Assert.True(d[0] == "5" && d[1] == "Test5")
                              );
        }
예제 #7
0
        public void RandomDoubling()
        {
            //Arrange
            TwoColumnsTableFixture source2Columns = new TwoColumnsTableFixture("RowMultiplicationSource");

            source2Columns.InsertTestData();

            DbSource <MySimpleRow>          source         = new DbSource <MySimpleRow>(SqlConnection, "RowMultiplicationSource");
            RowMultiplication <MySimpleRow> multiplication = new RowMultiplication <MySimpleRow>(
                row =>
            {
                List <MySimpleRow> result = new List <MySimpleRow>();
                for (int i = 0; i < row.Col1; i++)
                {
                    result.Add(new MySimpleRow()
                    {
                        Col1 = row.Col1 + i,
                        Col2 = "Test" + (row.Col1 + i)
                    });
                }
                return(result);
            });
            MemoryDestination <MySimpleRow> dest = new MemoryDestination <MySimpleRow>();

            //Act
            source.LinkTo(multiplication);
            multiplication.LinkTo(dest);
            source.Execute();
            dest.Wait();

            //Assert
            Assert.Collection(dest.Data,
                              d => Assert.True(d.Col1 == 1 && d.Col2 == "Test1"),
                              d => Assert.True(d.Col1 == 2 && d.Col2 == "Test2"),
                              d => Assert.True(d.Col1 == 3 && d.Col2 == "Test3"),
                              d => Assert.True(d.Col1 == 3 && d.Col2 == "Test3"),
                              d => Assert.True(d.Col1 == 4 && d.Col2 == "Test4"),
                              d => Assert.True(d.Col1 == 5 && d.Col2 == "Test5")
                              );
        }
        public void ThrowExceptionInFlow()
        {
            //Arrange
            TwoColumnsTableFixture source2Columns = new TwoColumnsTableFixture("RowMultiplicationSource");

            source2Columns.InsertTestData();

            DbSource <MySimpleRow>          source         = new DbSource <MySimpleRow>(SqlConnection, "RowMultiplicationSource");
            RowMultiplication <MySimpleRow> multiplication = new RowMultiplication <MySimpleRow>(
                row =>
            {
                List <MySimpleRow> result = new List <MySimpleRow>();
                result.Add(row);
                if (row.Col1 == 2)
                {
                    throw new Exception("Error in Flow!");
                }
                return(result);
            });
            MemoryDestination <MySimpleRow> dest      = new MemoryDestination <MySimpleRow>();
            MemoryDestination <ETLBoxError> errorDest = new MemoryDestination <ETLBoxError>();


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

            //Assert
            Assert.Collection <ETLBoxError>(errorDest.Data,
                                            d => Assert.True(!string.IsNullOrEmpty(d.RecordAsJson) && !string.IsNullOrEmpty(d.ErrorText))
                                            );
        }
예제 #9
0
        static void Main(string[] args)
        {
            XmlSource <Customer> source = new XmlSource <Customer>("XmlInputData.xml", ResourceType.File);

            source.XmlReaderSettings.DtdProcessing = System.Xml.DtdProcessing.Ignore;

            RowMultiplication <Customer, PaymentMethodAndCustomer> multi = new RowMultiplication <Customer, PaymentMethodAndCustomer>();

            multi.MultiplicationFunc =
                customer =>
            {
                List <PaymentMethodAndCustomer> result = new List <PaymentMethodAndCustomer>();
                foreach (PaymentMethod method in customer.PaymentMethods)
                {
                    var methodAndCustomer = new PaymentMethodAndCustomer();
                    /* Repeating data from customer */
                    methodAndCustomer.CustomerId   = customer.Id;
                    methodAndCustomer.CustomerName = customer.Name;

                    /* Specific data from payment methods */
                    methodAndCustomer.PaymentMethodType    = method.Type;
                    methodAndCustomer.PaymentMethodNumber  = method.Number;
                    methodAndCustomer.PaymentMethodValidTo = method.ValidTo;

                    result.Add(methodAndCustomer);
                }
                ;
                return(result);
            };

            MemoryDestination <PaymentMethodAndCustomer> dest = new MemoryDestination <PaymentMethodAndCustomer>();

            source.LinkTo(multi);
            multi.LinkTo(dest);

            Network.Execute(source);

            /* Display data */

            int lastid = 0;

            foreach (var methodAndCustomer in dest.Data)
            {
                if (lastid != methodAndCustomer.CustomerId)
                {
                    Console.WriteLine($"Customer Data: Id {methodAndCustomer.CustomerId}, Name '{methodAndCustomer.CustomerName}'");
                    lastid = methodAndCustomer.CustomerId;
                }
                Console.WriteLine($"   Payment method data: Type '{methodAndCustomer.PaymentMethodType}'," +
                                  $" Number '{methodAndCustomer.PaymentMethodNumber}', ValidTo '{methodAndCustomer.PaymentMethodValidTo}'");
            }

            /* Output */

            /* Customer Data: Id 1, Name 'Peter'
             *    Payment method data: Type 'Credit Card', Number '1234-5678', ValidTo '01/24'
             *    Payment method data: Type 'Wire transfer', Number 'AB12345435', ValidTo ''
             * Customer Data: Id 2, Name 'Mary'
             *    Payment method data: Type 'Credit Card', Number '4444-5555', ValidTo '12/26'
             *    Payment method data: Type 'Wire transfer', Number 'DA1234356', ValidTo ''
             *    Payment method data: Type 'PayPal', Number '*****@*****.**', ValidTo ''
             */
        }