public void AddFields() { int tag1 = 245; string[] indicators1 = new string[2] { "1", "0" }; List <string> subfields1 = new List <string> { "a", "Python", "c", "Guido" }; MARCField newField1 = new MARCField(tag1, indicators1, subfields1, ""); int tag2 = 245; string[] indicators2 = new string[2] { "1", "0" }; List <string> subfields2 = new List <string> { "a", "Lisp", "c", "Norvig" }; MARCField newField2 = new MARCField(tag2, indicators2, subfields2, ""); MARCRecord record = new MARCRecord(); record.AddFields(new MARCField[2] { newField1, newField2 }); Assert.Contains(newField1, record.Fields); Assert.Contains(newField2, record.Fields); }
public void Title() { int tag = 245; string[] indicators1 = new string[2] { "0", "1" }; List <string> subfields1 = new List <string> { "a", "Foo :", "b", "bar" }; MARCField field1 = new MARCField(tag, indicators1, subfields1); MARCRecord record1 = new MARCRecord(); record1.AddField(field1); Assert.Equals("Foo :bar", record1.Title); string[] indicators2 = new string[2] { "0", "1" }; List <string> subfields2 = new List <string> { "a", "Farghin" }; MARCField field2 = new MARCField(tag, indicators2, subfields2); MARCRecord record2 = new MARCRecord(); record2.AddField(field2); Assert.Equals("Farghin", record2.Title); }
public void GetFields() { MARCRecord record = new MARCRecord(); int tag1 = 650; string[] indicators1 = new string[2] { "", "0" }; List <string> subfields1 = new List <string> { "a", "Pogramming Language" }; MARCField subject1 = new MARCField(tag1, indicators1, subfields1, ""); int tag2 = 651; string[] indicators2 = new string[2] { "", "0" }; List <string> subfields2 = new List <string> { "a", "Object Oriented" }; MARCField subject2 = new MARCField(tag2, indicators2, subfields2, ""); record.AddFields(new MARCField[2] { subject1, subject2 }); Dictionary <int, MARCField[]> found = record.GetFields(new int[2] { 650, 651 }); Assert.Equals(found[650][0], subject1); Assert.Equals(found[651][0], subject2); }
public void ToStringTest() { string answer = @"=LDR 01201nam 2200253 a 4500 =001 tes96000001\ =003 ViArRB =005 199602210153555.7 =008 960221s1955\\\\dcuabcdjdbkoqu001\0deng\d =040 \\$aViArRB$cViArRB =050 \4$aPQ1234$b.T39 1955 =100 2\$aDeer-Doe, J.$q(Jane),$csaint,$d1355-1401,$cspirit. =245 10$aNew test record number 1 with ordinary data$h[large print] /$cby Jane Deer-Doe ; edited by Patty O'Furniture. =246 1\$aNew test record number one with ordinary data =260 \\$aWashington, DC :$bLibrary of Congress,$c1955-<1957> =300 \\$av. 1-<5> :$bill., maps, ports., charts ;$c cm. =440 \0$aTest record series ;$vno. 1 =500 \\$aThis is a test of ordinary features like replacement of the mnemonics for currency and dollar signs and backslashes (backsolidus \) used for blanks in certain areas. =500 \\$aThis is a test for the conversion of curly braces; the opening curly brace ({) and the closing curly brace (}). =504 \\$aIncludes Bibliographies, discographies, filmographies, and reviews. =500 \\$aIncludes index. =650 \4$aTest record$xJuvenile. =600 14$aDoe, John,$d1955- $xBiography. =700 1\$aO'Furniture, Patty,$eed. "; TextReader marcRecord = new StreamReader(@"C:\Documents and Settings\wkurt\My Documents\Visual Studio 2008\Projects\TestMARC\TestMARC\makrtest.mrc", Encoding.Default); string marcTransmission = marcRecord.ReadToEnd(); MARCRecord testRecord = new MARCRecord(marcTransmission); Assert.Equals(answer, testRecord.ToString()); }
public void RemoveFields() { TextReader marcRecord = new StreamReader(@"C:\Documents and Settings\wkurt\My Documents\Visual Studio 2008\Projects\TestMARC\TestMARC\makrtest.mrc", Encoding.Default); string marcTransmission = marcRecord.ReadToEnd(); MARCRecord testRecord = new MARCRecord(marcTransmission); //test when only one field is present string removed650and500 = @"=LDR 01201nam 2200253 a 4500 =001 tes96000001\ =003 ViArRB =005 199602210153555.7 =008 960221s1955\\\\dcuabcdjdbkoqu001\0deng\d =040 \\$aViArRB$cViArRB =050 \4$aPQ1234$b.T39 1955 =100 2\$aDeer-Doe, J.$q(Jane),$csaint,$d1355-1401,$cspirit. =245 10$aNew test record number 1 with ordinary data$h[large print] /$cby Jane Deer-Doe ; edited by Patty O'Furniture. =246 1\$aNew test record number one with ordinary data =260 \\$aWashington, DC :$bLibrary of Congress,$c1955-<1957> =300 \\$av. 1-<5> :$bill., maps, ports., charts ;$c cm. =440 \0$aTest record series ;$vno. 1 =504 \\$aIncludes Bibliographies, discographies, filmographies, and reviews. =600 14$aDoe, John,$d1955- $xBiography. =700 1\$aO'Furniture, Patty,$eed. "; testRecord.RemoveFields(new int[2] { 650, 500 }); Assert.Equals(removed650and500, testRecord.ToString()); }
public void GetField() { MARCRecord record = new MARCRecord(); int tag1 = 650; string[] indicators1 = new string[2] { "", "0" }; List <string> subfields1 = new List <string> { "a", "Pogramming Language" }; MARCField subject1 = new MARCField(tag1, indicators1, subfields1, ""); int tag2 = 650; string[] indicators2 = new string[2] { "", "0" }; List <string> subfields2 = new List <string> { "" }; MARCField subject2 = new MARCField(tag2, indicators2, subfields2, ""); record.AddFields(new MARCField[2] { subject1, subject2 }); MARCField[] found = record.GetField(650); Assert.Equals(found[0], subject1); Assert.Equals(found[1], subject2); }
public void FormatedLeader() { TextReader marcRecord = new StreamReader(@"C:\Documents and Settings\wkurt\My Documents\Visual Studio 2008\Projects\TestMARC\TestMARC\makrtest.mrc"); string marcTransmission = marcRecord.ReadToEnd(); MARCRecord testRecord = new MARCRecord(marcTransmission); Assert.Equals(@"=LDR 01201nam 2200253 a 4500", testRecord.FormatedLeader); }
private MARCRecord testProc(MARCRecord record) { record.AddField(new MARCField(999, new string[2] { "", "" }, new List <string> { "a", "hello there!" })); return(record); }
public void SaneRead() { char polishL = (char)0xa1; TextReader marcRecord = new StreamReader(@"C:\Documents and Settings\wkurt\My Documents\Visual Studio 2008\Projects\TestMARC\TestMARC\makrtest.mrc", Encoding.Default); string marcTransmission = marcRecord.ReadToEnd(); string record2 = marcTransmission.Split(MARCConstants.END_OF_RECORD)[1]; //basic check that the value is even in the record at all Assert.True(record2.Contains(polishL)); MARCRecord testRecord2 = new MARCRecord(record2); }
private void ReadRecord() { char[] headerBuffer = new char[5]; char[] recordBuffer; int recordLength; this.file.ReadBlock(headerBuffer, 0, 5); recordLength = Int32.Parse(new string(headerBuffer)); recordBuffer = new char[recordLength - headerBuffer.Length]; this.file.ReadBlock(recordBuffer, 0, recordLength - 5); this.current = new MARCRecord(new string(headerBuffer) + new string(recordBuffer)); }
public void AddField() { int tag = 245; string[] indicators = new string[2] { "1", "0" }; List <string> subfields = new List <string> { "a", "Python", "c", "Guido" }; MARCField newField = new MARCField(tag, indicators, subfields, ""); MARCRecord record = new MARCRecord(); record.AddField(newField); Assert.Contains(newField, record.Fields); }
public void DecodeMARC() { TextReader marcRecord = new StreamReader(@"C:\Documents and Settings\wkurt\My Documents\Visual Studio 2008\Projects\TestMARC\TestMARC\makrtest.mrc"); string marcTransmission = marcRecord.ReadToEnd(); MARCRecord testRecord = new MARCRecord(marcTransmission);//decode should happen automatically here Assert.Equals("4", testRecord.GetField(50)[0].Indicator2); Assert.Equals(@"=008 960221s1955\\\\dcuabcdjdbkoqu001\0deng\d", testRecord.GetField(8)[0].ToString()); //Assert.Equals(@"=050 \4$aPQ1234$b.T39 1955", testRecord.GetField(50)[0].ToString()); Assert.Equals(@"=260 \\$aWashington, DC :$bLibrary of Congress,$c1955-<1957>", testRecord.GetField(260)[0].ToString()); Assert.Equals(@"=040 \\$aViArRB$cViArRB", testRecord.GetField(40)[0].ToString()); Assert.Equals(@"=600 14$aDoe, John,$d1955- $xBiography.", testRecord.GetField(600)[0].ToString()); marcRecord.Close(); }
public void ProcessThenWriteSingeRecord() { MARCWriter proctest = new MARCWriter(@"proctest.dat"); MARCRecord procrecord = new MARCRecord(); proctest.ProcessThenWrite(new MARCWriter.MARCProcess(testProc), procrecord); proctest.Close(); MARCReader test = new MARCReader(@"proctest.dat"); foreach (MARCRecord record in test) { string testValue = record.GetField(999)[0].FormatField(); Assert.Equals("hello there!", testValue); } test.Close(); }
public void AsMARC21() { TextReader marcRecord = new StreamReader(@"C:\Documents and Settings\wkurt\My Documents\Visual Studio 2008\Projects\TestMARC\TestMARC\makrtest.mrc"); string marcTransmission = marcRecord.ReadToEnd(); MARCRecord testRecord = new MARCRecord(marcTransmission);//decode should happen automatically here //right now I cannot check the header info Assert.True(marcTransmission.Contains(testRecord.AsMARC21())); marcRecord.Close(); TextReader singleMarcRecord = new StreamReader(@"C:\Documents and Settings\wkurt\My Documents\Visual Studio 2008\Projects\TestMARC\TestMARC\one.dat"); string singleMarc = singleMarcRecord.ReadToEnd(); MARCRecord singleTest = new MARCRecord(singleMarc); Assert.Equals(singleMarc, singleTest.AsMARC21()); singleMarcRecord.Close(); }
public void Author() { int tag = 100; string[] indicators = new string[] { "1", "0" }; List <string> subfields = new List <string> { "a", "Bletch, Foobie,", "d", "1979-1981." }; MARCField field = new MARCField(tag, indicators, subfields); MARCRecord record = new MARCRecord(); record.AddField(field); Assert.Equals("Bletch, Foobie, 1979-1981.", record.Author); MARCRecord blankRecord = new MARCRecord(); Assert.Null(blankRecord.Author); }
public void ISBN() { int tag = 20; string[] indicators = new string[] { "0", "1" }; List <string> subfields = new List <string> { "a", "123456789" }; MARCRecord record = new MARCRecord(); MARCField field = new MARCField(tag, indicators, subfields); record.AddField(field); Assert.Equals("123456789", record.ISBN); MARCRecord blankRecord = new MARCRecord(); Assert.Null(blankRecord.ISBN); }
public void MapField() { //test the case of 1:1 mapping int tag = 245; string[] indicators = new string[2] { "1", "0" }; List <string> subfields = new List <string> { "a", "Python", "c", "Guido" }; MARCField newField = new MARCField(tag, indicators, subfields, ""); MARCRecord record = new MARCRecord(); record.AddField(newField); record.MapField(245, 300); Assert.Equals(0, record.GetField(245).Length); Assert.Equals(1, record.GetField(300).Length); }
public void SortFields() { MARCRecord messyRecord = new MARCRecord(); messyRecord.AddField(new MARCField(999 , new string[2] { "1", "0" } , new List <string> { "a", "stuff" })); messyRecord.AddField(new MARCField(645 , new string[2] { "1", "0" } , new List <string> { "b", "more stuff" })); messyRecord.AddField(new MARCField(1 , new string[2] { "1", "0" } , new List <string> { "c", "zmore stuff" })); messyRecord.AddField(new MARCField(997 , new string[2] { "1", "0" } , new List <string> { "d", "stuffs stuff" })); messyRecord.SortFields(); MARCField[] sortedFields = messyRecord.Fields.ToArray(); for (int i = 0; i < sortedFields.Length - 1; i++) { Assert.True(Int32.Parse(sortedFields[i].tag) < Int32.Parse(sortedFields[i + 1].tag)); } }
public void MediumNumberOfRecordsWithRecordArrays() { string toWriteFile = "groupsmedium.dat"; string source = @"C:\Documents and Settings\wkurt\My Documents\Visual Studio 2008\Projects\TestMARC\TestMARC\makrtest.mrc"; MARCWriter groups = new MARCWriter(toWriteFile); MARCReader ourHumbleReader = new MARCReader(source); MARCRecord[] recordGroup = new MARCRecord[5]; int i = 0; foreach (MARCRecord record in ourHumbleReader) { if (i == 5) { i = 0; groups.Write(recordGroup); } recordGroup[i] = record; i++; } for (int j = 0; j < i; j++) { groups.Write(recordGroup[j]); } groups.Close(); StreamReader answer = new StreamReader(source, Encoding.Default); StreamReader result = new StreamReader(toWriteFile); char[] answerBuffer = new char[1]; char[] resultBuffer = new char[1]; while (answer.Peek() != -1 && result.Peek() != -1) { answer.ReadBlock(answerBuffer, 0, 1); result.ReadBlock(resultBuffer, 0, 1); Assert.Equals(answerBuffer[0], resultBuffer[0]); } }
public void HasField() { int tag = 245; string[] indicators = new string[2] { "1", "0" }; List <string> subfields = new List <string> { "a", "Python", "c", "Guido" }; MARCField newField = new MARCField(tag, indicators, subfields, ""); MARCRecord record = new MARCRecord(); record.AddField(newField); Assert.True(record.HasField(245)); Assert.False(record.HasField(300)); //test after a map record.MapField(245, 300); Assert.True(record.HasField(300)); Assert.False(record.HasField(245)); }
public void OneRecordWrite() { string answer = new StreamReader(@"C:\Documents and Settings\wkurt\My Documents\Visual Studio 2008\Projects\TestMARC\TestMARC\one.mrk").ReadToEnd(); MARCBreakerWriter file = new MARCBreakerWriter("breakerOneTest.mrk"); MARCReader reader = new MARCReader(@"C:\Documents and Settings\wkurt\My Documents\Visual Studio 2008\Projects\TestMARC\TestMARC\one.dat"); MARCRecord theRecord = new MARCRecord(); foreach (MARCRecord record in reader) { theRecord = record; } file.Write(theRecord); file.Close(); string result = new StreamReader("breakerOneTest.mrk").ReadToEnd(); //only checks that all of the characters so far are the same, not that the strings are identical for (int i = 0; i < answer.Length && i < result.Length; i++) { Assert.Equals(answer[i], result[i], "difference at " + i + " of " + result.Length + "\n " + (char)answer[i] + " v. " + (char)result[i]); } Assert.Equals(answer.Length, result.Length, "The answer differs by " + (answer.Length - result.Length).ToString()); }
public virtual void Write(MARCRecord record) { this.fileStream.Write(record.AsMARC21()); }
/* * Applies a process to a record, and then write that record. * note: the process must return a MARCrecord */ public void ProcessThenWrite(MARCProcess process, MARCRecord record) { Write(process(record)); }
public void MARCMakerFormat() { string answer = @"=LDR 01201nam 2200253 a 4500 =001 tes96000001\ =003 ViArRB =005 199602210153555.7 =008 960221s1955\\\\dcuabcdjdbkoqu001\0deng\d =040 \\$aViArRB$cViArRB =050 \4$aPQ1234$b.T39 1955 =100 2\$aDeer-Doe, J.$q(Jane),$csaint,$d1355-1401,$cspirit. =245 10$aNew test record number 1 with ordinary data$h[large print] /$cby Jane Deer-Doe ; edited by Patty O'Furniture. =246 1\$aNew test record number one with ordinary data =260 \\$aWashington, DC :$bLibrary of Congress,$c1955-<1957> =300 \\$av. 1-<5> :$bill., maps, ports., charts ;$c cm. =440 \0$aTest record series ;$vno. 1 =500 \\$aThis is a test of ordinary features like replacement of the mnemonics for currency and dollar signs and backslashes (backsolidus \) used for blanks in certain areas. =500 \\$aThis is a test for the conversion of curly braces; the opening curly brace ({lcub}) and the closing curly brace ({rcub}). =504 \\$aIncludes Bibliographies, discographies, filmographies, and reviews. =500 \\$aIncludes index. =650 \4$aTest record$xJuvenile. =600 14$aDoe, John,$d1955- $xBiography. =700 1\$aO'Furniture, Patty,$eed." + "\r\n\r\n"; string answer2 = @"=LDR 02665nam 2200229 a 4500 =001 tes96000002\ =003 ViArRB =005 19960221075055.7 =008 960221s1955\\\\dcuabcdjdbkoqu001\0dspa\d =020 \\$a8472236579 =040 \\$aViArRB$cViArRB =050 \4$aPQ1234$b.T39 1955 =100 2\$aDeer-Doe, Jane,$d1957- =245 10$aNew test record number 2 with currently defined ANSEL characters (mostly diacritics) input with their real hexadecimal values$h[large print] /$cby Jane Deer-Doe =260 \\$aWashington, DC :$bLibrary of Congress,$c1955. =300 \\$a300 p. :$bill., maps, ports., charts ;$c cm. =440 \0$aTest record series ;$vno. 2 =500 \\$aThis is a test of diacritics like the uppercase Polish L in {Lstrok}{acute}od{acute}z, the uppercase Scandinavia O in {Ostrok}st, the uppercase D with crossbar in {Dstrok}uro, the uppercase Icelandic thorn in {THORN}ann, the uppercase digraph AE in {AElig}gir, the uppercase digraph OE in {OElig}uvres, the soft sign in rech{softsign}, the middle dot in col{middot}lecci{acute}o, the musical flat in F{flat}, the patent mark in Frizbee{reg}, the plus or minus sign in {plusmn}54%, the uppercase O-hook in B{Ohorn}, the uppercase U-hook in X{Uhorn}A, the alif in mas{mlrhring}alah, the ayn in {mllhring}arab, the lowercase Polish l in W{lstrok}oc{lstrok}aw, the lowercase Scandinavian o in K{ostrok}benhavn, the lowercase d with crossbar in {dstrok}avola, the lowercase Icelandic thorn in {thorn}ann, the lowercase digraph ae in v{aelig}re, the lowercase digraph oe in c{oelig}ur, the lowercase hardsign in s{hardsign}ezd, the Turkish dotless i in masal{inodot}, the British pound sign in {pound}5.95, the lowercase eth in ver{eth}ur, the lowercase o-hook (with pseudo question mark) in S{hooka}{ohorn}, the lowercase u-hook in T{uhorn} D{uhorn}c, the pseudo question mark in c{hooka}ui, the grave accent in tr{grave}es, the acute accent in d{acute}esir{acute}ee, the circumflex in c{circ}ote, the tilde in ma{tilde}nana, the macron in T{macr}okyo, the breve in russki{breve}i, the dot above in {dot}zaba, the dieresis (umlaut) in L{uml}owenbr{uml}au, the caron (hachek) in {caron}crny, the circle above (angstrom) in {ring}arbok, the ligature first and second halves in d{llig}i{rlig}ad{llig}i{rlig}a, the high comma off center in rozdel{rcommaa}ovac, the double acute in id{dblac}oszaki, the candrabindu (breve with dot above) in Ali{candra}iev, the cedilla in {cedil}ca va comme {cedil}ca, the right hook in viet{ogon}a, the dot below in te{dotb}da, the double dot below in {under}k{under}hu{dbldotb}tbah, the circle below in Sa{dotb}msk{ringb}rta, the double underscore in {dblunder}Ghulam, the left hook in Lech Wa{lstrok}{commab}esa, the right cedilla (comma below) in kh{rcedil}ong, the upadhmaniya (half circle below) in {breveb}humantu{caron}s, double tilde, first and second halves in {ldbltil}n{rdbltil}galan, high comma (centered) in g{commaa}eotermika =504 \\$aIncludes Bibliographies, discographies, filmographies, and reviews. =500 \\$aIncludes index. =650 \4$aTest record$xJuvenile. =600 14$aDoe, John,$d1955- $xBiography." + "\r\n\r\n"; TextReader marcRecord = new StreamReader(@"C:\Documents and Settings\wkurt\My Documents\Visual Studio 2008\Projects\TestMARC\TestMARC\makrtest.mrc", Encoding.Default); string marcTransmission = marcRecord.ReadToEnd(); string record2 = marcTransmission.Split(MARCConstants.END_OF_RECORD)[1]; MARCRecord testRecord = new MARCRecord(marcTransmission); Assert.Equals(answer, testRecord.MARCMakerFormat()); MARCRecord testRecord2 = new MARCRecord(record2); StringReader resultStream = new StringReader(testRecord2.MARCMakerFormat()); StringReader answerStream = new StringReader(answer2); while (resultStream.Peek() != -1 && answerStream.Peek() != -1) { string answerLine = answerStream.ReadLine(); string resultLine = resultStream.ReadLine(); Assert.Equals(answerLine, resultLine, CharDiff(answerLine, resultLine)); } }
public override void Write(MARCRecord record) { fileStream.Write(record.MARCMakerFormat()); }
public void TestRecordLeaderInvalid() { string data = "foo"; MARCRecord record = new MARCRecord(data); }
public void TestBaseAddressInvalid() { string data = "00695cam 2200241Ia 45x00"; MARCRecord record = new MARCRecord(data); }