Example #1
0
        public void WrongType()
        {
            string     text   = "01732:Juan Perez:0100.00:11/05/2002";
            TextFields fields = new TextFields(text.Split(':'));

            fields.GetInt32(1);
        }
Example #2
0
        public void FailsIfBadIndex()
        {
            string     text   = "01732:Juan Perez:0100.00:11/05/2002";
            TextFields fields = new TextFields(text.Split(':'));

            fields.GetString(4);
        }
Example #3
0
        public void ItemCount()
        {
            string     text   = "01732:Juan Perez:0100.00:11/05/2002";
            TextFields fields = new TextFields(text.Split(':'));

            Assert.AreEqual(4, fields.Count);
        }
Example #4
0
        public void CanParseSingleField()
        {
            string text = "single record";

            using (StringReader reader = new StringReader(text))
            {
                using (FixedWidthFieldParser parser = new FixedWidthFieldParser(reader))
                {
                    TextFields fields = parser.ReadFields();
                    Assert.AreEqual(1, fields.Count);
                    Assert.AreEqual(text, fields[0]);
                }
            }
        }
Example #5
0
        public void CanTreatQuotesAsNormalChars()
        {
            string text = "Michael \"Magic\" Jordan";

            using (StringReader reader = new StringReader(text))
            {
                using (DelimitedFieldParser parser = new DelimitedFieldParser(reader))
                {
                    parser.HasFieldsEnclosedInQuotes = false;
                    TextFields fields = parser.ReadFields();
                    Assert.AreEqual(1, fields.Count);
                    Assert.AreEqual(text, fields[0]);
                }
            }
        }
Example #6
0
        public void CanReadTypedFields()
        {
            string text = "01732Juan Perez     0100.0011/05/2002";

            using (StringReader reader = new StringReader(text))
            {
                using (FixedWidthFieldParser parser = new FixedWidthFieldParser(reader))
                {
                    parser.SetFieldWidths(5, 15, 7, 10);
                    parser.TrimWhiteSpace = true;

                    TextFields fields = parser.ReadFields();
                    Assert.AreEqual(1732, fields.GetInt32(0));
                    Assert.AreEqual("Juan Perez", fields.GetString(1));
                    Assert.AreEqual(100.0f, fields.GetSingle(2));
                    Assert.AreEqual(new DateTime(2002, 11, 05), fields.GetDateTime(3));
                }
            }
        }
Example #7
0
        public void FieldsTypes()
        {
            string     text   = "01732:Juan Perez:0100.00:11/05/2002";
            TextFields fields = new TextFields(text.Split(':'));

            Assert.AreEqual("01732", fields[0]);
            Assert.AreEqual(1732, fields.GetInt16(0));
            Assert.AreEqual(1732, fields.GetInt32(0));
            Assert.AreEqual(1732, fields.GetInt64(0));

            Assert.AreEqual("Juan Perez", fields.GetString(1));

            Assert.AreEqual("0100.00", fields[2]);
            Assert.AreEqual(100.00f, fields.GetSingle(2));
            Assert.AreEqual(100.00f, fields.GetDouble(2));

            Assert.AreEqual("11/05/2002", fields[3]);
            Assert.AreEqual(new DateTime(2002, 11, 05), fields.GetDateTime(3));
        }