public async Task Test_FitsReader(FitsFileInfo testCaseData) { var path = Path.Combine(ReaderWriter_TestCaseDataProvider.TestDataDirectory, testCaseData.Name); Assume.That(File.Exists(path)); await using var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read); await using var fitsReader = new FitsReader(fileStream, 0, true); var counter = 0; await foreach (var block in fitsReader.EnumerateBlocksAsync()) { Assume.That(counter, Is.LessThan(testCaseData.NumUnits)); Assert.That(block.Keys.Count, Is.EqualTo(testCaseData.NumKeywordsPerUnit[counter++])); TestContext.Out.WriteLine((counter, block.Keys.Count)); } Assert.That(counter, Is.EqualTo(testCaseData.NumUnits)); }
public async Task Test_FitsReader_FitsWrite(FitsFileInfo testCaseData) { var path = Path.Combine(ReaderWriter_TestCaseDataProvider.TestDataDirectory, testCaseData.Name); Assume.That(File.Exists(path)); List <Block> content; List <Block> reReadContent; await using (var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read)) { await using var reader = new FitsReader(fileStream); content = await reader.EnumerateBlocksAsync().ToListAsync(); } await using var memStr = new MemoryStream(); { await using (var writer = new FitsWriter(memStr)) foreach (var block in content) { await writer.WriteBlockAsync(block); } memStr.Seek(0, SeekOrigin.Begin); await using var reader = new FitsReader(memStr); reReadContent = await reader.EnumerateBlocksAsync().ToListAsync(); } Assert.AreEqual(content.Count, reReadContent.Count); for (var i = 0; i < content.Count; i++) { CollectionAssert.AreEqual(content[i].Keys, reReadContent[i].Keys); Assert.IsTrue(content[i].RawData.SequenceEqual(reReadContent[i].RawData)); } }