public void TestCtor_Options_TextNull_Throws()
 {
     Stream stream = null;
     FixedLengthSchema schema = new FixedLengthSchema();
     FixedLengthParserOptions options = new FixedLengthParserOptions();
     new FixedLengthParser(stream, schema, options);
 }
 public void TestCtor_Options_SchemaNull_Throws()
 {
     string text = String.Empty;
     FixedLengthSchema schema = null;
     FixedLengthParserOptions options = new FixedLengthParserOptions();
     new FixedLengthParser(new MemoryStream(Encoding.Default.GetBytes(text)), schema, options);
 }
Exemple #3
0
        public void TestCtor_OptionsNull_Throws()
        {
            string                   text    = String.Empty;
            FixedLengthSchema        schema  = new FixedLengthSchema();
            FixedLengthParserOptions options = null;

            new FixedLengthParser(new MemoryStream(Encoding.Default.GetBytes(text)), schema, options);
        }
Exemple #4
0
        public void TestCtor_Options_TextNull_Throws()
        {
            Stream                   stream  = null;
            FixedLengthSchema        schema  = new FixedLengthSchema();
            FixedLengthParserOptions options = new FixedLengthParserOptions();

            new FixedLengthParser(stream, schema, options);
        }
Exemple #5
0
        public void TestGetValues_CustomFillCharacter_TrimsFill()
        {
            const string      text   = "@@@@@@@123@@@@@@@@@@@@@@@@@@@@@@Bob@1/19/2013";
            FixedLengthSchema schema = new FixedLengthSchema();

            schema.AddColumn(new Int32Column("id"), 10)
            .AddColumn(new StringColumn("name"), 25)
            .AddColumn(new DateTimeColumn("created"), 10);
            FixedLengthParserOptions options = new FixedLengthParserOptions()
            {
                FillCharacter = '@'
            };
            FixedLengthParser parser = new FixedLengthParser(new MemoryStream(Encoding.Default.GetBytes(text)), schema, options);

            Assert.IsTrue(parser.Read(), "Could not read the first record.");
            object[] expected = new object[] { 123, "Bob", new DateTime(2013, 1, 19) };
            object[] actual   = parser.GetValues();
            CollectionAssert.AreEqual(expected, actual, "The values for the first record were wrong.");
        }
Exemple #6
0
        public void TestGetValues_CustomRecordSeparator_SplitsFile()
        {
            const string      text   = "       123                      Bob 1/19/2013BOOM       234                      Sam12/20/2013";
            FixedLengthSchema schema = new FixedLengthSchema();

            schema.AddColumn(new Int32Column("id"), 10)
            .AddColumn(new StringColumn("name"), 25)
            .AddColumn(new DateTimeColumn("created"), 10);
            FixedLengthParserOptions options = new FixedLengthParserOptions()
            {
                RecordSeparator = "BOOM"
            };
            FixedLengthParser parser = new FixedLengthParser(new MemoryStream(Encoding.Default.GetBytes(text)), schema, options);

            Assert.IsTrue(parser.Read(), "Could not read the first record.");
            object[] expected = new object[] { 123, "Bob", new DateTime(2013, 1, 19) };
            object[] actual   = parser.GetValues();
            CollectionAssert.AreEqual(expected, actual, "The values for the first record were wrong.");

            Assert.IsTrue(parser.Read(), "Could not read the second record.");
            expected = new object[] { 234, "Sam", new DateTime(2013, 12, 20) };
            actual   = parser.GetValues();
            CollectionAssert.AreEqual(expected, actual, "The values for the second record were wrong.");
        }
        public void TestGetValues_CustomRecordSeparator_SplitsFile()
        {
            const string text = "       123                      Bob 1/19/2013BOOM       234                      Sam12/20/2013";
            FixedLengthSchema schema = new FixedLengthSchema();
            schema.AddColumn(new Int32Column("id"), 10)
                  .AddColumn(new StringColumn("name"), 25)
                  .AddColumn(new DateTimeColumn("created"), 10);
            FixedLengthParserOptions options = new FixedLengthParserOptions() { RecordSeparator = "BOOM" };
            FixedLengthParser parser = new FixedLengthParser(new MemoryStream(Encoding.Default.GetBytes(text)), schema, options);

            Assert.IsTrue(parser.Read(), "Could not read the first record.");
            object[] expected = new object[] { 123, "Bob", new DateTime(2013, 1, 19) };
            object[] actual = parser.GetValues();
            CollectionAssert.AreEqual(expected, actual, "The values for the first record were wrong.");

            Assert.IsTrue(parser.Read(), "Could not read the second record.");
            expected = new object[] { 234, "Sam", new DateTime(2013, 12, 20) };
            actual = parser.GetValues();
            CollectionAssert.AreEqual(expected, actual, "The values for the second record were wrong.");
        }
        public void TestGetValues_CustomFillCharacter_TrimsFill()
        {
            const string text = "@@@@@@@123@@@@@@@@@@@@@@@@@@@@@@Bob@1/19/2013";
            FixedLengthSchema schema = new FixedLengthSchema();
            schema.AddColumn(new Int32Column("id"), 10)
                  .AddColumn(new StringColumn("name"), 25)
                  .AddColumn(new DateTimeColumn("created"), 10);
            FixedLengthParserOptions options = new FixedLengthParserOptions() { FillCharacter = '@' };
            FixedLengthParser parser = new FixedLengthParser(new MemoryStream(Encoding.Default.GetBytes(text)), schema, options);

            Assert.IsTrue(parser.Read(), "Could not read the first record.");
            object[] expected = new object[] { 123, "Bob", new DateTime(2013, 1, 19) };
            object[] actual = parser.GetValues();
            CollectionAssert.AreEqual(expected, actual, "The values for the first record were wrong.");
        }