示例#1
0
        public void ReadStreamWithExtraColumnsInBetween()
        {
            // arrange
            string data = "Field3,Field4,Field5,Inbetween1,Field1,Field2,More1,More2" + Environment.NewLine +
                          "3,4,5,i,1,2,a,b" + Environment.NewLine;
            var engine = new DelimitedFileEngine <SampleType5Fields>();

            // act
            engine.SetFieldOrder(new string[] { "Field3", "Field4", "Field5", "Inbetween1", "Field1", "Field2" });
            TextReader textReader = new StringReader(data);

            SampleType5Fields[] res;
            res = engine.ReadStream(textReader, int.MaxValue);

            // assert
            Assert.AreEqual(1, res.Length);
            Assert.AreEqual(1, engine.TotalRecords);
            Assert.AreEqual(0, engine.ErrorManager.ErrorCount);

            Assert.AreEqual("1", res[0].Field1);
            Assert.AreEqual("2", res[0].Field2);
            Assert.AreEqual("3", res[0].Field3);
            Assert.AreEqual("4", res[0].Field4);
            Assert.AreEqual("5", res[0].Field5);
        }
示例#2
0
        public void ReadStreamWithDifferentColumnOrder()
        {
            // arrange
            string data = "Field3,Field4,Field5,Field1,Field2" + Environment.NewLine +
                          "3,4,5,1,2" + Environment.NewLine +
                          "33,44,55,11,22" + Environment.NewLine;
            var engine = new DelimitedFileEngine <SampleType5Fields>();

            // act
            engine.SetFieldOrder(new string[] { "Field3", "Field4", "Field5", "Field1", "Field2" });
            TextReader textReader = new StringReader(data);

            SampleType5Fields[] res;
            res = engine.ReadStream(textReader, int.MaxValue);

            // assert
            Assert.AreEqual(2, res.Length);
            Assert.AreEqual(2, engine.TotalRecords);
            Assert.AreEqual(0, engine.ErrorManager.ErrorCount);

            Assert.AreEqual("1", res[0].Field1);
            Assert.AreEqual("2", res[0].Field2);
            Assert.AreEqual("3", res[0].Field3);
            Assert.AreEqual("4", res[0].Field4);
            Assert.AreEqual("5", res[0].Field5);

            Assert.AreEqual("11", res[1].Field1);
            Assert.AreEqual("22", res[1].Field2);
            Assert.AreEqual("33", res[1].Field3);
            Assert.AreEqual("44", res[1].Field4);
            Assert.AreEqual("55", res[1].Field5);
        }
示例#3
0
        public void StandardImport_WithExtraColumnsInMiddleAndColumnOrdering()
        {
            // arrange
            var engine = new DelimitedFileEngine <FieldOrderType>();

            engine.Options.IgnoreEmptyLines = true;
            engine.ErrorMode = ErrorMode.SaveAndContinue;
            engine.SetFieldOrder(fields_withextrainmiddle);

            // act
            var res = engine.ReadStream(new StringReader(data_WithExtraFieldsInMiddle), Int32.MaxValue).ToList();

            // assert
            Assert.IsFalse(engine.ErrorManager.HasErrors);
            Assert.IsTrue(res.Count == 2);
            Validate_Data_Standard(res);
        }
示例#4
0
        public void ReOrderDelimitedFields()
        {
            // arrange
            var           engine   = new DelimitedFileEngine <FieldOrderType>();
            List <string> newOrder = new List <string>()
            {
                "Field5", "Field4", "Field3"
            };

            // act
            //engine.SetFieldOrder(newOrder);
            engine.SetFieldOrder(newOrder.ToArray());

            // assert
            Assert.AreEqual(6, engine.Options.FieldCount);
            Assert.AreEqual("Field5", engine.Options.FieldsNames[0]);
            Assert.AreEqual("Field4", engine.Options.FieldsNames[1]);
            Assert.AreEqual("Field3", engine.Options.FieldsNames[2]);
            Assert.AreEqual("Field1", engine.Options.FieldsNames[3]);
            Assert.AreEqual("Field2", engine.Options.FieldsNames[4]);
        }