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

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

                    await jfr.ReadAsync(dpd.CancellationToken);

                    Assert.AreEqual("level", jfr.GetColumn(1).Name);
                    Assert.AreEqual("Error", jfr.GetValue(1));

                    await jfr.ReadAsync(dpd.CancellationToken);

                    Assert.AreEqual("Reading EdgeAPI vw_rpt_transcript", jfr.GetValue(2));

                    await jfr.ReadAsync(dpd.CancellationToken);

                    Assert.AreEqual("System.Data.DataException", jfr.GetValue(4));
                }
        }
Exemplo n.º 2
0
        public async Task ReadJSon3Async()
        {
            var setting = new CsvFile(UnitTestInitializeCsv.GetTestPath("Jason3.json"))
            {
                JsonFormat = true
            };

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

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

                    Assert.AreEqual(28L, jfr.GetValue(0));
                    await jfr.ReadAsync(dpd.CancellationToken);

                    Assert.AreEqual(56L, jfr.GetValue(0));
                    while (await jfr.ReadAsync(dpd.CancellationToken))
                    {
                    }

                    Assert.AreEqual(5, jfr.RecordNumber);
                }
        }
Exemplo n.º 3
0
        public async Task ReadJSon2Async()
        {
            var setting = new CsvFile(UnitTestInitializeCsv.GetTestPath("Jason2.json"))
            {
                JsonFormat = true
            };

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

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

                    await jfr.ReadAsync(dpd.CancellationToken);

                    Assert.AreEqual("Loading defaults C:\\Users\\rnoldner\\AppData\\Roaming\\CSVFileValidator\\Setting.xml",
                                    jfr.GetValue(6));
                    while (await jfr.ReadAsync(dpd.CancellationToken))
                    {
                    }

                    Assert.AreEqual(29, jfr.RecordNumber);
                }
        }
Exemplo n.º 4
0
        public async Task ReadJSon1Async()
        {
            var setting = new CsvFile(UnitTestInitializeCsv.GetTestPath("Jason1.json"))
            {
                JsonFormat = true
            };

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

                    Assert.AreEqual(20, jfr.FieldCount);
                    await jfr.ReadAsync(processDisplay.CancellationToken);

                    Assert.AreEqual("5048fde7c4aa917cbd4d8e13", jfr.GetValue(0));
                    await jfr.ReadAsync(processDisplay.CancellationToken);

                    Assert.AreEqual("5048fde7c4aa917cbd4d22333", jfr.GetValue(0));
                    Assert.AreEqual(2, jfr.RecordNumber);
                }
        }
Exemplo n.º 5
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);
                }
        }
Exemplo n.º 6
0
        public async Task OpenJsonArray()
        {
            var setting =
                new CsvFile(UnitTestInitializeCsv.GetTestPath("Larger.json.gz"))
            {
                JsonFormat = true
            };

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

                    Assert.AreEqual("object_id", jfr.GetName(0));
                    Assert.AreEqual("_last_touched_dt_utc", jfr.GetName(1));

                    await jfr.ReadAsync(dpd.CancellationToken);

                    Assert.AreEqual("ef21069c-3d93-4e07-878d-00e820727f65", jfr.GetString(0));
                    Assert.IsTrue((new DateTime(2020, 04, 03, 20, 45, 29, DateTimeKind.Local) - (DateTime)jfr.GetValue(1))
                                  .TotalSeconds < 1f);
                }
        }