コード例 #1
0
        public void TestFileRead1()
        {
            string path = Environment.CurrentDirectory + "/config-1.csv";

            if (!File.Exists(path))
            {
                throw new Exception("file not found");
            }
            CsvConfigReader reader = new CsvConfigReader();

            reader.ReadFile(path);

            CsvValue value = reader[1]["key12"].Value;

            string[] stringArray = value;
            Assert.AreEqual(5, stringArray.Length);
            Assert.AreEqual("hello,001", stringArray[0]);
            Assert.AreEqual("hello,002", stringArray[1]);
            Assert.AreEqual("hello,003", stringArray[2]);
            Assert.AreEqual("hello,004", stringArray[3]);
            Assert.AreEqual("hello,005", stringArray[4]);
            bool[] boolArray = reader[1]["key9"].Value;
            foreach (bool b in boolArray)
            {
                Assert.IsTrue(b);
            }
        }
コード例 #2
0
        public void TestFileRead()
        {
            string path = Environment.CurrentDirectory + "/config.csv";

            if (!File.Exists(path))
            {
                throw new Exception("file not found");
            }
            CsvConfigReader reader = new CsvConfigReader();

            reader.ReadFile(path);
            Assert.AreEqual(7, reader.FieldNames.Count);
            Assert.AreEqual("key", reader.FieldNames[0]);
            Assert.AreEqual("nameBool", reader.FieldNames[1]);
            Assert.AreEqual("nameInt", reader.FieldNames[2]);
            Assert.AreEqual("nameLong", reader.FieldNames[3]);
            Assert.AreEqual("nameFloat", reader.FieldNames[4]);
            Assert.AreEqual("nameDouble", reader.FieldNames[5]);
            Assert.AreEqual("nameString", reader.FieldNames[6]);
            Assert.AreEqual(100, reader.Keys.Count);
            Assert.AreEqual(CsvValueType.Int, reader.KeyType);
            for (int i = 1; i <= 100; i++)
            {
                if (i < 26 || (i > 50 && i < 76))
                {
                    Assert.True(reader[i]["nameBool"].Value);
                }
                else
                {
                    Assert.False(reader[i]["nameBool"].Value);
                }
                Assert.AreEqual(100 + i, reader[i]["nameInt"].Value);
                Assert.AreEqual(1000 + i, reader[i]["nameLong"].Value);
                Assert.AreEqual(0 + 0.01f * i, reader[i]["nameFloat"].Value, 0.00001f);
                Assert.AreEqual(1 + 0.01f * i, reader[i]["nameDouble"].Value, 0.00001f);
                string s = i < 10 ? "a0" + i :  "a" + i;
                Assert.AreEqual(s, reader[i]["nameString"].Value.Value);//need implicit to string
            }
        }