public void ShouldDecryptFile() { using (var fsEncrypted = new FileStream("Resources/encrypted-a.tps", FileMode.Open)) using (var fsUnencrypted = new FileStream("Resources/not-encrypted.tps", FileMode.Open)) { var encryptedFile = new RandomAccessTpsFile(fsEncrypted, new Key("a")); var decryptedFile = new RandomAccessTpsFile(fsUnencrypted); var encryptedDefinitions = encryptedFile.GetTableDefinitions(ignoreErrors: false); var decryptedDefinitions = decryptedFile.GetTableDefinitions(ignoreErrors: false); Assert.AreEqual(decryptedDefinitions.Count, encryptedDefinitions.Count); // Note that record IDs may differ. var encryptedRecords = encryptedFile.GetDataRecords(table: 2, tableDefinition: encryptedDefinitions[2], ignoreErrors: false); var decryptedRecords = decryptedFile.GetDataRecords(table: 1, tableDefinition: decryptedDefinitions[1], ignoreErrors: false); Assert.AreEqual(decryptedRecords.Count(), encryptedRecords.Count()); var zip = decryptedRecords.Zip(encryptedRecords, (d, e) => (dec: d, enc: e)); foreach (var(dec, enc) in zip) { CollectionAssert.AreEqual(dec.Values, enc.Values); } } }
public void ShouldReadFromFile() { using (var stream = new FileStream("Resources/table-with-time.tps", FileMode.Open)) { var file = new RandomAccessTpsFile(stream); var tableDef = file.GetTableDefinitions(false).First().Value; var record = file.GetDataRecords(1, tableDef, false).First(); var valuePairs = record.GetFieldValuePairs(); Assert.AreEqual(new TimeSpan(0, 6, 23, 15, 0), valuePairs["ClockIn"].Value); Assert.AreEqual(new TimeSpan(0, 12, 59, 59, 0), valuePairs["ClockOut"].Value); } }