public async Task ReadJSon1TypedAsync() { var setting = new CsvFile(UnitTestInitializeCsv.GetTestPath("Larger.json")) { JsonFormat = true }; using (var processDisplay = new CustomProcessDisplay(UnitTestInitializeCsv.Token)) { using (var jfr = new JsonFileReader(setting, processDisplay)) { await jfr.OpenAsync(processDisplay.CancellationToken); await jfr.ReadAsync(processDisplay.CancellationToken); Assert.AreEqual(new Guid("ef21069c-3d93-4e07-878d-00e820727f65"), jfr.GetGuid(0)); Assert.IsTrue((new DateTime(2020, 04, 03, 18, 45, 29, 573, DateTimeKind.Utc) - jfr.GetDateTime(1).ToUniversalTime()).TotalSeconds < 2); Assert.AreEqual((short)0, jfr.GetInt16(5)); Assert.AreEqual((int)0, jfr.GetInt32(5)); Assert.AreEqual((long)0, jfr.GetInt64(5)); var val = new object[jfr.FieldCount]; jfr.GetValues(val); Assert.IsNull(val[2]); } } }
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); } }