public void TestNullableExtensions_AllNotNull()
        {
            string data = String.Join(",", new object[]
            {
                (byte)0,                                            // Byte
                (short)1,                                           // Short
                2,                                                  // Int
                3L,                                                 // Long
                4f,                                                 // Float
                5.0,                                                // Double
                6m,                                                 // Decimal
                "abc",                                              // String
                new DateTime(2018, 07, 08),                         // DateTime
                new Guid("{2E13CDEB-6A06-4A79-A446-B057F2881406}"), // Guid
                DayOfWeek.Sunday                                    // Enum
            });
            var schema       = GetSchema();
            var stringReader = new StringReader(data);
            var csvReader    = new SeparatedValueReader(stringReader, schema);
            var dataReader   = new FlatFileDataReader(csvReader);

            Assert.IsTrue(dataReader.Read(), "A record was not read.");
            Assert.AreEqual((byte)0, dataReader.GetNullableByte(0), "The byte was not null.");
            Assert.AreEqual((short)1, dataReader.GetNullableInt16(1), "The byte was not null.");
            Assert.AreEqual(2, dataReader.GetNullableInt32(2), "The byte was not null.");
            Assert.AreEqual(3L, dataReader.GetNullableInt64(3), "The byte was not null.");
            Assert.AreEqual(4f, dataReader.GetNullableFloat(4), "The byte was not null.");
            Assert.AreEqual(5.0, dataReader.GetNullableDouble(5), "The byte was not null.");
            Assert.AreEqual(6m, dataReader.GetNullableDecimal(6), "The byte was not null.");
            Assert.AreEqual("abc", dataReader.GetNullableString(7), "The byte was not null.");
            Assert.AreEqual(new DateTime(2018, 07, 08), dataReader.GetNullableDateTime(8), "The byte was not null.");
            Assert.AreEqual(new Guid("{2E13CDEB-6A06-4A79-A446-B057F2881406}"), dataReader.GetNullableGuid(9), "The byte was not null.");
            Assert.AreEqual(DayOfWeek.Sunday, dataReader.GetNullableEnum <DayOfWeek>(10), "The byte was not null.");
            Assert.IsFalse(dataReader.Read(), "Too many records were read.");
        }
Esempio n. 2
0
        public void ShouldGetRecordsFromReader()
        {
            FlatFileDataReader dataReader = GetFlatFileReader();

            Assert.IsTrue(dataReader.Read(), "The first record could not be read.");
            Assert.AreEqual(1, dataReader.GetInt32("Id"), "The wrong 'Id' was retrieved for 'Bob'.");
            Assert.AreEqual("Bob", dataReader.GetString("Name"), "The wrong 'Name' was retrieved for 'Bob'.");
            Assert.AreEqual(new DateTime(2018, 07, 03), dataReader.GetDateTime("CreatedOn"), "The wrong 'CreatedOn' was retrieved for 'Bob'.");
            Assert.IsTrue(dataReader.GetBoolean("IsActive"), "The wrong 'IsActive' was retrieved for 'Bob'");
            Assert.AreEqual(10, dataReader.GetNullableInt32("VisitCount"), "The wrong 'VisitCount' was retrieved for 'Bob'.");

            Assert.IsTrue(dataReader.Read(), "The second record could not be read.");
            Assert.AreEqual(2, dataReader.GetInt32("Id"), "The wrong 'Id' was retrieved for 'Susan'.");
            Assert.AreEqual("Susan", dataReader.GetString("Name"), "The wrong 'Name' was retrieved for 'Susan'.");
            Assert.AreEqual(new DateTime(2018, 07, 04), dataReader.GetDateTime("CreatedOn"), "The wrong 'CreatedOn' was retrieved for 'Susan'.");
            Assert.IsFalse(dataReader.GetBoolean("IsActive"), "The wrong 'IsActive' was retrieved for 'Susan'");
            Assert.AreEqual(null, dataReader.GetNullableInt32("VisitCount"), "The wrong 'VisitCount' was retrieved for 'Susan'.");

            Assert.IsFalse(dataReader.Read(), "Too many records were read.");
        }
        public void TestNullableExtensions_AllNull()
        {
            string data         = String.Join(",", typeof(NullableValues).GetProperties().Select(x => (string)null));
            var    schema       = GetSchema();
            var    stringReader = new StringReader(data);
            var    csvReader    = new SeparatedValueReader(stringReader, schema);
            var    dataReader   = new FlatFileDataReader(csvReader);

            Assert.IsTrue(dataReader.Read(), "A record was not read.");
            Assert.IsNull(dataReader.GetNullableByte(0), "The byte was not null.");
            Assert.IsNull(dataReader.GetNullableInt16(1), "The byte was not null.");
            Assert.IsNull(dataReader.GetNullableInt32(2), "The byte was not null.");
            Assert.IsNull(dataReader.GetNullableInt64(3), "The byte was not null.");
            Assert.IsNull(dataReader.GetNullableFloat(4), "The byte was not null.");
            Assert.IsNull(dataReader.GetNullableDouble(5), "The byte was not null.");
            Assert.IsNull(dataReader.GetNullableDecimal(6), "The byte was not null.");
            Assert.IsNull(dataReader.GetNullableString(7), "The byte was not null.");
            Assert.IsNull(dataReader.GetNullableDateTime(8), "The byte was not null.");
            Assert.IsNull(dataReader.GetNullableGuid(9), "The byte was not null.");
            Assert.IsNull(dataReader.GetNullableEnum <DayOfWeek>(10), "The byte was not null.");
            Assert.IsFalse(dataReader.Read(), "Too many records were read.");
        }