Exemplo n.º 1
0
        public async Task ReadJSonEmpAsync()
        {
            var setting = new CsvFile(UnitTestInitializeCsv.GetTestPath("Emp.json"))
            {
                JsonFormat = true
            };

            using (var dpd = new CustomProcessDisplay(UnitTestInitializeCsv.Token))
                using (var jfr = new JsonFileReader(setting, dpd))
                {
                    await jfr.OpenAsync(dpd.CancellationToken);

                    Assert.AreEqual(110, jfr.FieldCount);
                    await jfr.ReadAsync(dpd.CancellationToken);

                    Assert.AreEqual("String", jfr.GetDataTypeName(0));
                    Assert.AreEqual("43357099", jfr.GetValue(0));
                    Assert.AreEqual("T454898", jfr.GetValue(1));
                    Assert.AreEqual(new DateTime(2012, 02, 06), jfr.GetValue(jfr.GetOrdinal("LastHireDate")));
                    Assert.IsTrue(jfr.IsDBNull(jfr.GetOrdinal("ASSIGN_2ND_DEPT")));
                    Assert.AreEqual((short)0, jfr.GetInt16(jfr.GetOrdinal("Approvals")));
                    Assert.AreEqual(0, jfr.GetInt32(jfr.GetOrdinal("Approvals")));
                    Assert.AreEqual(0L, jfr.GetInt64(jfr.GetOrdinal("Approvals")));
                    Assert.AreEqual(0f, jfr.GetFloat(jfr.GetOrdinal("Approvals")));
                    Assert.AreEqual(0, jfr.GetDecimal(jfr.GetOrdinal("Approvals")));
                    Assert.AreEqual(0, jfr.GetDouble(jfr.GetOrdinal("Approvals")));
                    Assert.IsTrue(jfr.GetBoolean(2));
                    Assert.AreEqual(1.000, jfr.GetValue(jfr.GetOrdinal("FTE")));
                    _ = await jfr.ReadAsync(dpd.CancellationToken);

                    Assert.AreEqual("43357196", jfr.GetValue(0));
                    _ = await jfr.ReadAsync(dpd.CancellationToken);

                    Assert.AreEqual("43357477", jfr.GetValue(0));
                    // read each column in each row
                    while (await jfr.ReadAsync(dpd.CancellationToken))
                    {
                        for (var i = 0; i < jfr.FieldCount; i++)
                        {
                            jfr.GetValue(i);
                        }
                    }
                    Assert.AreEqual(2782, jfr.RecordNumber);
                }
        }