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 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 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 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 RemoveField(int tag) { MARCField[] fieldsArray = new MARCField[this.fields.ToArray().Length]; this.fields.CopyTo(fieldsArray); foreach (MARCField field in fieldsArray) { if (Int32.Parse(field.tag) == tag) { this.fields.Remove(field); } } }
public void AddSubfield() { int tag = 245; string[] indicators = new string[2] { "0", "1" }; List <string> subfields = new List <string> { "a", "foo" }; MARCField testField = new MARCField(tag, indicators, subfields, ""); testField.AddSubfield("a", "bar"); Assert.Equals("=245 01$afoo$abar", testField.ToString()); }
//compares marcfields for SortFields //btw I know this is ugly but this is actually based on the *example* code //msdn gives. private static int CompareFields(MARCField field1, MARCField field2) { if (field1 == null) { if (field2 == null) { //both fields null, they are equal return(0); } else { //only field1 is null < return(-1); } } else { if (field2 == null) { if (field1 == null) { //again both null return(0); } else { return(1); } } //all cases of nulls have been delt with else { int diff = Int32.Parse(field1.tag) - Int32.Parse(field2.tag); if (diff == 0) { return(0); } else if (diff < 0) { return(-1); } else { return(0); } } } }
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 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 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 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 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 TestToString() { Assert.Equals("=245 01$aHuckleberry Finn: $bAn American Odyssey", testObject1.ToString()); Assert.Equals(@"=008 831227m19799999nyu\\\\\\\\\\\|||\|\ger\\", testObjectControl.ToString()); // =040 \\$aViArRB$cViArRB string answer = @"=040 \\$aViArRB$cViArRB"; int testTag = 40; string[] indicators = new string[2] { "", "" }; List <string> subfields = new List <string> { "a", "ViArRB", "c", "ViArRB" }; MARCField testField = new MARCField(testTag, indicators, subfields); Assert.Equals(answer, testField.ToString()); Assert.Equals(@"=500 \\$aThis is a test for the conversion of curly braces; the opening curly brace ({) and the closing curly brace (}).", testObjectCurly.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 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 SetUp() { //title field object int tag1 = 245; string[] indicators1 = new string[2] { "0", "1" }; List<string> subfields1 = new List<string> { "a", "Huckleberry Finn: ", "b", "An American Odyssey" }; string data1 = ""; testObject1 = new MARCField(tag1, indicators1, subfields1, data1); //control field object int tag2 = 8; string[] indicators2 = new string[0];//empty array List<string> subfields2 = null; //null? string data2 = "831227m19799999nyu ||| | ger "; testObjectControl = new MARCField(tag2, indicators2, subfields2, data2); //subject field test int tag3 = 650; string[] indicators3 = new string[2] { " ", "0" }; List<string> subfields3 = new List<string>{ "a", "Python (Computer program language)", "v", "Poetry." }; string data3 = ""; testObjectSubject = new MARCField(tag3, indicators3, subfields3, data3); //curly brackets test //string answer3 = @"=500 \\$aThis is a test for the conversion of curly braces; the opening curly brace ({lcub}) and the closing curly brace ({rcub})."; int tag4 = 500; string[] indicators4 = new string[2] {"",""}; List<string> subfields4 = new List<string> { "a", "This is a test for the conversion of curly braces; the opening curly brace ({) and the closing curly brace (})." }; testObjectCurly = new MARCField(tag4,indicators4,subfields4); int tag5 = 500; string[] indicators5 = new string[2] { "", "" }; List<string> subfields5 = new List<string> { "a", @"This is a test of diacritics like the uppercase Polish L in " + (char)0xa1 + (char)0xe2 + "od" + (char)0xe2 + "z, the uppercase Scandinavia O in " + (char)0xa2 + "st, the uppercase D with crossbar in " + (char)0xa3 + "uro, the uppercase Icelandic thorn in " + (char)0xa4 + "ann, the uppercase digraph AE in " + (char)0xa5 + "gir" }; testObjectNonASCIIChars = new MARCField(tag5, indicators5, subfields5); }
public void TestToString() { Assert.Equals("=245 01$aHuckleberry Finn: $bAn American Odyssey", testObject1.ToString()); Assert.Equals(@"=008 831227m19799999nyu\\\\\\\\\\\|||\|\ger\\", testObjectControl.ToString()); // =040 \\$aViArRB$cViArRB string answer= @"=040 \\$aViArRB$cViArRB"; int testTag = 40; string[] indicators = new string[2] { "", "" }; List<string> subfields = new List<string> { "a", "ViArRB", "c", "ViArRB" }; MARCField testField = new MARCField(testTag, indicators, subfields); Assert.Equals(answer,testField.ToString()); Assert.Equals(@"=500 \\$aThis is a test for the conversion of curly braces; the opening curly brace ({) and the closing curly brace (}).", testObjectCurly.ToString()); }
public void CleanUp() { testObject1 = null; testObjectControl = null; }
public void SetUp() { //title field object int tag1 = 245; string[] indicators1 = new string[2] { "0", "1" }; List <string> subfields1 = new List <string> { "a", "Huckleberry Finn: ", "b", "An American Odyssey" }; string data1 = ""; testObject1 = new MARCField(tag1, indicators1, subfields1, data1); //control field object int tag2 = 8; string[] indicators2 = new string[0]; //empty array List <string> subfields2 = null; //null? string data2 = "831227m19799999nyu ||| | ger "; testObjectControl = new MARCField(tag2, indicators2, subfields2, data2); //subject field test int tag3 = 650; string[] indicators3 = new string[2] { " ", "0" }; List <string> subfields3 = new List <string> { "a", "Python (Computer program language)", "v", "Poetry." }; string data3 = ""; testObjectSubject = new MARCField(tag3, indicators3, subfields3, data3); //curly brackets test //string answer3 = @"=500 \\$aThis is a test for the conversion of curly braces; the opening curly brace ({lcub}) and the closing curly brace ({rcub})."; int tag4 = 500; string[] indicators4 = new string[2] { "", "" }; List <string> subfields4 = new List <string> { "a", "This is a test for the conversion of curly braces; the opening curly brace ({) and the closing curly brace (})." }; testObjectCurly = new MARCField(tag4, indicators4, subfields4); int tag5 = 500; string[] indicators5 = new string[2] { "", "" }; List <string> subfields5 = new List <string> { "a", @"This is a test of diacritics like the uppercase Polish L in " + (char)0xa1 + (char)0xe2 + "od" + (char)0xe2 + "z, the uppercase Scandinavia O in " + (char)0xa2 + "st, the uppercase D with crossbar in " + (char)0xa3 + "uro, the uppercase Icelandic thorn in " + (char)0xa4 + "ann, the uppercase digraph AE in " + (char)0xa5 + "gir" }; testObjectNonASCIIChars = new MARCField(tag5, indicators5, subfields5); }
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 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); }
/* * decode_marc() accepts a MARC record in transmission format as a * a string argument, and will populate the object based on the data * found. * */ public void DecodeMARC(string marcRecord) { if (marcRecord.Length < MARCConstants.LEADER_LEN) { throw new RecordLeaderInvalid(); } //extract record leader this.leader = marcRecord.Substring(0, MARCConstants.LEADER_LEN); // extract the byte offset where the record data starts int baseAddress = Int32.Parse(marcRecord.Substring(12, 5)); if (baseAddress < 0) { throw new BaseAddressNotFound(); } if (baseAddress >= marcRecord.Length) { throw new BaseAddressInvalid(); } //extract directory, base_address-1 is used since the //directory ends with an END_OF_FIELD byte string directory = marcRecord.Substring(MARCConstants.LEADER_LEN, (baseAddress - 1) - MARCConstants.LEADER_LEN); //determine number of fields in a record if (directory.Length % MARCConstants.DIRECTORY_ENTRY_LEN != 0) { throw new RecordDirectoryInvalid(); } int fieldTotal = directory.Length / MARCConstants.DIRECTORY_ENTRY_LEN; //if there are no fields then raise error if (fieldTotal == 0) { throw new NoFieldsFound(); } //add fields to the record for (int fieldCount = 0; fieldCount < fieldTotal; fieldCount++) { MARCField field; int entryStart = fieldCount * MARCConstants.DIRECTORY_ENTRY_LEN; int entryEnd = entryStart + MARCConstants.DIRECTORY_ENTRY_LEN; string entry = directory.Substring(entryStart, entryEnd - entryStart); int entryTag = Int32.Parse(entry.Substring(0, 3)); int entryLength = Int32.Parse(entry.Substring(3, 4)); int entryOffset = Int32.Parse(entry.Substring(7, 5)); string entryData = marcRecord.Substring(baseAddress + entryOffset, entryLength - 1); if (entryTag < 010) { field = new MARCField(entryTag, entryData); } else { string[] marcSubfields = entryData.Split(MARCConstants.SUBFIELD_INDICATOR); List <string> subfields = new List <string> { }; int indicatorsArrayLength = marcSubfields[0].Length; string entryIndicator1; string entryIndicator2; if (indicatorsArrayLength > 1) { entryIndicator1 = marcSubfields[0][0].ToString(); entryIndicator2 = marcSubfields[0][1].ToString(); } else if (indicatorsArrayLength == 1) { entryIndicator1 = marcSubfields[0][0].ToString(); entryIndicator2 = ""; } else { entryIndicator1 = ""; entryIndicator2 = ""; } string[] entryIndicators = new string[2] { entryIndicator1, entryIndicator2 }; for (int i = 1; i < marcSubfields.Length; i++) { //not sure about this exactly if (marcSubfields[i].Length != 0) { string code = marcSubfields[i].Substring(0, 1); string data = marcSubfields[i].Substring(1); subfields.Add(code); subfields.Add(data); } } field = new MARCField(entryTag, entryIndicators, subfields); } this.AddField(field); } }
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 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 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 AddField(MARCField field) { this.fields.Add(field); }
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 AddSubfield() { int tag = 245; string[] indicators = new string[2] { "0", "1" }; List<string> subfields = new List<string> { "a", "foo" }; MARCField testField = new MARCField(tag,indicators,subfields,""); testField.AddSubfield("a", "bar"); Assert.Equals("=245 01$afoo$abar", testField.ToString()); }