Exemple #1
0
        public void TestLoadPropertiesAndFieldsSameName()
        {
            // It's ok to have newline with padding at start, should trim field names (not values)
            // Include spaces in string field value to prove all content preserved
            string csvData = @"StringMember, Hello World  ,This is an ignored description,also ignored
			EnumMember,Blue,Something Something
			IntMember,1234,Comment here
			FloatMember,1.5,More commenting"            ;

            TestPropertiesAndFieldsObject t = new TestPropertiesAndFieldsObject();

            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(csvData))) {
                using (var sr = new StreamReader(ms)) {
                    CsvUtil.LoadObject(sr, ref t);
                }
            }

            Assert.AreEqual(" Hello World  ", t.StringMember);
            Assert.AreEqual(" Hello World  ", t.GetStringField());
            Assert.AreEqual(1234, t.IntMember);
            Assert.AreEqual(1234, t.GetIntField());
            Assert.That(t.FloatMember, Is.InRange(1.4999f, 1.5001f));     // float imprecision
            Assert.That(t.GetFloatField(), Is.InRange(1.4999f, 1.5001f)); // float imprecision
            Assert.AreEqual(TestPropertiesAndFieldsObject.Colour.Blue, t.EnumMember);
            Assert.AreEqual(TestPropertiesAndFieldsObject.Colour.Blue, t.GetEnumField());
        }
Exemple #2
0
    public void TestLoadPropertiesAndFieldsSameName()
    {
        // It's ok to have newline with padding at start, should trim field names (not values)
        // Include spaces in string field value to prove all content preserved
        string csvData = @"StringMember, Hello World  ,This is an ignored description,also ignored
			EnumMember,Blue,Something Something
			IntMember,1234,Comment here
			FloatMember,1.5,More commenting"            ;

        TestPropertiesAndFieldsObject t = new TestPropertiesAndFieldsObject();

        using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(csvData)))
        {
            using (var sr = new StreamReader(ms))
            {
                CsvUtil.LoadObject(sr, ref t);
            }
        }
    }