Пример #1
0
        public void SourceWithDifferentNames()
        {
            //Arrange
            TwoColumnsTableFixture            dest2Columns = new TwoColumnsTableFixture("XmlSource2ColsDynamic");
            RowTransformation <ExpandoObject> trans        = new RowTransformation <ExpandoObject>(
                row =>
            {
                dynamic r = row as ExpandoObject;
                r.Col1    = r.Column1;
                r.Col2    = r.Column2;
                return(r);
            });
            DbDestination <ExpandoObject> dest = new DbDestination <ExpandoObject>("XmlSource2ColsDynamic", Connection);

            //Act
            XmlSource <ExpandoObject> source = new XmlSource <ExpandoObject>("res/XmlSource/TwoColumnsElementDifferentNames.xml", ResourceType.File)
            {
                ElementName = "MySimpleRow"
            };
            var link1 = source.LinkTo(trans);
            var link2 = link1.source.LinkTo(dest);

            using (link1.link)
                using (link2.link)
                {
                    source.Execute();
                    dest.Wait();

                    //Assert
                    dest2Columns.AssertTestData();
                }
        }
        public void WithoutErrorLinking()
        {
            //Arrange
            MemoryDestination <MySimpleRow> dest = new MemoryDestination <MySimpleRow>();

            //Act
            XmlSource <MySimpleRow> source = new XmlSource <MySimpleRow>("res/XmlSource/TwoColumnsErrorLinking.xml", ResourceType.File);

            //Assert
            Assert.Throws <System.InvalidOperationException>(() =>
            {
                source.LinkTo(dest);
                source.Execute();
                dest.Wait();
            });
        }
Пример #3
0
        public void XmlOnlyAttributes()
        {
            //Arrange
            TwoColumnsTableFixture         dest2Columns = new TwoColumnsTableFixture("XmlSource2ColsAttribute");
            DbDestination <MyAttributeRow> dest         = new DbDestination <MyAttributeRow>(Connection, "XmlSource2ColsAttribute");

            //Actt
            XmlSource <MyAttributeRow> source = new XmlSource <MyAttributeRow>("res/XmlSource/TwoColumnsOnlyAttributes.xml", ResourceType.File);

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

            //Assert
            dest2Columns.AssertTestData();
        }
        public void WithObjectErrorLinking()
        {
            //Arrange
            TwoColumnsTableFixture          dest2Columns = new TwoColumnsTableFixture("XmlSourceErrorLinking");
            DbDestination <MySimpleRow>     dest         = new DbDestination <MySimpleRow>(SqlConnection, "XmlSourceErrorLinking");
            MemoryDestination <ETLBoxError> errorDest    = new MemoryDestination <ETLBoxError>();

            //Act
            XmlSource <MySimpleRow> source = new XmlSource <MySimpleRow>("res/XmlSource/TwoColumnsErrorLinking.xml",
                                                                         ResourceType.File);

            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))
                                            );
        }
Пример #5
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 ''
             */
        }