public void TestConvertToXMLNormalizedRoundtrip() { MemoryStream out1 = null; using (var input = new FileStream(Environment.CurrentDirectory + StaticTestRecords.RESOURCES_BRKRTEST_MRC, FileMode.Open)) { Assert.IsNotNull(input); out1 = new MemoryStream(); MarcStreamReader marcReader = new MarcStreamReader(input); MarcXmlWriter xmlWriter = new MarcXmlWriter(out1); xmlWriter.Converter = new AnselToUnicode(); xmlWriter.UnicodeNormalization = true; while (marcReader.MoveNext()) { var record = marcReader.Current; xmlWriter.Write(record); } input.Close(); xmlWriter.Close(); out1.Close(); } using (MemoryStream out2 = new MemoryStream()) { using (MemoryStream @in = new MemoryStream(out1.ToArray())) { var xmlReader = new MarcXmlReader(@in).GetEnumerator(); MarcStreamWriter marcWriter = new MarcStreamWriter(out2); marcWriter.Converter = new UnicodeToAnsel(); while (xmlReader.MoveNext()) { var record = xmlReader.Current; marcWriter.Write(record); } @in.Close(); marcWriter.Close(); out2.Close(); using (var inputCompare1 = new FileStream(Environment.CurrentDirectory + StaticTestRecords.RESOURCES_BRKRTEST_MRC, FileMode.Open)) { Assert.IsNotNull(inputCompare1); var inputCompare2 = new MemoryStream(out2.ToArray()); MarcStreamReader readComp1 = new MarcStreamReader(inputCompare1); MarcStreamReader readComp2 = new MarcStreamReader(inputCompare2); IRecord r1, r2; do { r1 = (readComp1.MoveNext()) ? readComp1.Current : null; r2 = (readComp2.MoveNext()) ? readComp2.Current : null; if (r1 != null && r2 != null) { RecordTestingUtils.AssertEqualsIgnoreLeader(r1, r2); } } while (r1 != null && r2 != null); } } } }
public void TestMarcXmlWriter() { using (var ms = new MemoryStream()) { MarcXmlWriter writer = new MarcXmlWriter(ms, true); foreach (var record in StaticTestRecords.summerland) { writer.Write(record); } writer.Close(); ms.Position = 0; using (var sr = new StreamReader(ms)) TestUtils.ValidateStringAgainstFile(sr.ReadToEnd(), StaticTestRecords.RESOURCES_SUMMERLAND_XML); } }