public void TestMethod1() { var path = Folder + @"DB.DBF"; var version = DbfVersion.dBASE_IV_SQL_Table; var w0 = new object[] { true, DateTime.Today, "HELLO!!!", 20001000.34, 345.780 }; var w1 = new object[] { false, DateTime.Today.AddDays(-51), "BYE!!!", 10002000.34, 780.345 }; IReadOnlyList <DbfField> fields; { using var writer = new DbfWriter(path, version); Assert.AreEqual(version, writer.Version); //dbf.AddField(new DbfField("INTFIELD", DbfFieldType.Integer)); writer.AddField(new DbfField("LGCFIELD", DbfFieldType.Logical)); writer.AddField(new DbfField("DATFIELD", DbfFieldType.Date)); writer.AddField(new DbfField("CHRFIELD", DbfFieldType.Character, 10)); writer.AddField(new DbfField("NUMFIELD", DbfFieldType.Numeric, 10, 2)); writer.AddField(new DbfField("FLTFIELD", DbfFieldType.Float)); Assert.AreEqual(5, writer.Fields.Count); writer.AddRecord(w0); writer.AddRecord(w1); fields = writer.Fields; } { using var reader = new DbfReader(path); // Header Assert.AreEqual(version, reader.Version); Assert.AreEqual(fields.Count, reader.Fields.Count); Assert.IsTrue(fields.Select(x => x.Name).Zip(reader.Fields.Select(x => x.Name)).All(x => x.First.Equals(x.Second))); Assert.IsTrue(fields.Select(x => x.Type).Zip(reader.Fields.Select(x => x.Type)).All(x => x.First.Equals(x.Second))); Assert.IsTrue(fields.Select(x => x.Length).Zip(reader.Fields.Select(x => x.Length)).All(x => x.First.Equals(x.Second))); Assert.IsTrue(fields.Select(x => x.Precision).Zip(reader.Fields.Select(x => x.Precision)).All(x => x.First.Equals(x.Second))); Assert.IsTrue(fields.Zip(reader.Fields).All(x => x.First.Equals(x.Second))); // Records Assert.AreEqual(2, reader.RecordCount); var r0 = reader.Read(); Assert.IsNotNull(r0); var r1 = reader.Read(); Assert.IsNotNull(r1); CollectionAssert.AreEqual(w0, r0); CollectionAssert.AreEqual(w1, r1); } }
public void TestRecordCount() { var rdr = new DbfReader(GetDbfStream()); uint count = 0; while (rdr.Read()) { count++; } Assert.AreEqual(rdr.RecordCount, count); }
public void TestRecords() { var rdr = new DbfReader(GetDbfStream()); Assert.AreEqual(6, rdr.Fields.Length); for (int i = 0; i < 5; i++) { Assert.AreEqual(true, rdr.Read()); for (int j = 0; j < 6; j++) { Assert.AreEqual(testData[j][i], rdr[j]); } } }
public void DbfReadSimpleFile() { var f = new DataFile() { Encoding = Encoding.GetEncoding(866) }; var rdr = new DbfReader(f); using (var file = File.Open("../../testfiles/simple.dbf", FileMode.Open)) { rdr.Read(file); } var wrt = new DbfWriter(f); using (var file = File.Open("../../testfiles/output.dbf", FileMode.OpenOrCreate | FileMode.Truncate)) { wrt.Write(file); } ProviderTools.CompareFiles("../../testfiles/simple.dbf", "../../testfiles/output.dbf"); }
public void DbfReadAutoEncoding() { var f = new DataFile() { Encoding = null // AUTO }; var rdr = new DbfReader(f); using (var file = File.Open("../../testfiles/ENCODING.dbf", FileMode.Open)) { rdr.Read(file); } var wrt = new DbfWriter(f); using (var file = File.Open("../../testfiles/output.dbf", FileMode.OpenOrCreate | FileMode.Truncate)) { wrt.Write(file); } ProviderTools.CompareFiles("../../testfiles/ENCODING.dbf", "../../testfiles/output.dbf"); }