예제 #1
0
        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);
                    }
                }
            }
        }
예제 #2
0
        public void TestWriteAndReadRoundtripConverted()
        {
            MemoryStream out2 = null;

            using (var input = new FileStream(Environment.CurrentDirectory + StaticTestRecords.RESOURCES_BRKRTEST_MRC, FileMode.Open))
            {
                Assert.IsNotNull(input);
                var out1 = new MemoryStream();
                MarcStreamReader marcReader1 = new MarcStreamReader(input);
                MarcStreamWriter marcWriter1 = new MarcStreamWriter(out1, "UTF-8");
                marcWriter1.Converter = new AnselToUnicode();
                while (marcReader1.MoveNext())
                {
                    var record = marcReader1.Current;
                    marcWriter1.Write(record);
                }
                input.Close();
                marcWriter1.Close();
                out1.Close();
                out2 = new MemoryStream();
                var @in = new MemoryStream(out1.ToArray());
                MarcStreamReader marcReader2 = new MarcStreamReader(@in);
                MarcStreamWriter marcWriter2 = new MarcStreamWriter(out2);
                marcWriter2.Converter = new UnicodeToAnsel();
                while (marcReader2.MoveNext())
                {
                    var record = marcReader2.Current;
                    marcWriter2.Write(record);
                }
                @in.Close();
            }

            using (var inputCompare1 = new FileStream(Environment.CurrentDirectory + StaticTestRecords.RESOURCES_BRKRTEST_MRC, FileMode.Open))
            {
                var     inputCompare2 = out2;
                var     readComp1 = new MarcStreamReader(inputCompare1);
                var     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);
            }

            out2.Dispose();
        }
예제 #3
0
        public void TestWriteAndReadRoundtrip()
        {
            MemoryStream out2 = null;

            using (var input = new FileStream(Environment.CurrentDirectory + StaticTestRecords.RESOURCES_CHABON_MRC, FileMode.Open))
            {
                Assert.IsNotNull(input);
                using (var out1 = new MemoryStream())
                {
                    MarcStreamReader marcReader = new MarcStreamReader(input);
                    using (MarcXmlWriter xmlWriter = new MarcXmlWriter(out1))
                    {
                        while (marcReader.MoveNext())
                        {
                            var record = marcReader.Current;
                            xmlWriter.Write(record);
                        }
                    }
                    out2 = new MemoryStream();
                    var @in       = new MemoryStream(out1.ToArray());
                    var xmlReader = new MarcXmlReader(@in).GetEnumerator();
                    MarcStreamWriter marcWriter = new MarcStreamWriter(out2);
                    while (xmlReader.MoveNext())
                    {
                        var record = xmlReader.Current;
                        marcWriter.Write(record);
                    }
                    @in.Close();
                }
            }
            using (var inputCompare1 = new FileStream(Environment.CurrentDirectory + StaticTestRecords.RESOURCES_CHABON_MRC, FileMode.Open))
            {
                var     inputCompare2 = out2;
                var     readComp1 = new MarcStreamReader(inputCompare1);
                var     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);
            }
            out2.Dispose();
        }