//Private utility functions #region Private utility functions /// <summary> /// Decodes the raw MARC record into a <see cref="MARC.Record"/> at the specified index. /// </summary> /// <param name="index">The index of the record to retrieve.</param> /// <returns></returns> private Record decode(int index) { XElement record = rawSource[index]; Record marcXML = new Record { Leader = record.Elements().First(e => e.Name.LocalName == "leader").Value }; //First we get the leader //Now we get the control fields foreach (XElement controlField in record.Elements().Where(e => e.Name.LocalName == "controlfield")) { ControlField newField = new ControlField(controlField.Attribute("tag").Value, controlField.Value); marcXML.Fields.Add(newField); } //Now we get the data fields foreach (XElement dataField in record.Elements().Where(e => e.Name.LocalName == "datafield")) { DataField newField = new DataField(dataField.Attribute("tag").Value, new List <Subfield>(), dataField.Attribute("ind1").Value[0], dataField.Attribute("ind2").Value[0]); foreach (XElement subfield in dataField.Elements().Where(e => e.Name.LocalName == "subfield")) { Subfield newSubfield = new Subfield(subfield.Attribute("code").Value[0], subfield.Value); newField.Subfields.Add(newSubfield); } marcXML.Fields.Add(newField); } return(marcXML); }
public void CloneTest() { string tag = "001"; string data = " 2007032296"; ControlField target = new ControlField(tag, data); Field expected = target; Field actual; actual = target.Clone(); Assert.AreNotEqual(expected, actual); target.Data = " 2011063096"; string expectedString = data; string actualString; actualString = ((ControlField)actual).Data; Assert.AreEqual(expectedString, actualString); target.Tag = "002"; expectedString = tag; actualString = ((ControlField)actual).Tag; Assert.AreEqual(expectedString, actualString); }
/// <summary> /// Decodes the raw MARC record into a <see cref="MARC.Record"/> at the specified index./// /// </summary> /// <param name="index">The index of the record to retrieve.</param> /// <returns></returns> private Record Decode(int index) { XElement record = _rawSource[index]; Record marcXml = new Record(); //First we get the leader marcXml.Leader = record.Elements().First(e => e.Name.LocalName == "leader").Value; //Now we get the control fields foreach (XElement controlField in record.Elements().Where(e => e.Name.LocalName == "controlfield")) { ControlField newField = new ControlField(controlField.Attribute("tag").Value, controlField.Value); marcXml.Fields.Add(newField); } //Now we get the data fields foreach (XElement dataField in record.Elements().Where(e => e.Name.LocalName == "datafield")) { DataField newField = new DataField(dataField.Attribute("tag").Value, new List<Subfield>(), dataField.Attribute("ind1").Value[0], dataField.Attribute("ind2").Value[0]); foreach (XElement subfield in dataField.Elements().Where(e => e.Name.LocalName == "subfield")) { Subfield newSubfield = new Subfield(subfield.Attribute("code").Value[0], subfield.Value); newField.Subfields.Add(newSubfield); } marcXml.Fields.Add(newField); } return marcXml; }
/// <summary> /// Makes a deep clone of this instance. /// </summary> /// <returns></returns> public override Field Clone() { Field clone = new ControlField(tag, data); return(clone); }
public void ItemTest() { Record target = new Record(); string tag = "245"; ControlField controlField = new ControlField("001", "I am data! (But not Data from Star Trek TNG)"); DataField dataField = new DataField(tag); DataField dataField2 = new DataField(tag, new List<Subfield>(), ' ', '1'); target.Fields.Add(controlField); target.Fields.Add(dataField); target.Fields.Add(dataField2); Field expected = dataField; Field actual; actual = target[tag]; }
public void FieldsTest() { Record target = new Record(); ControlField controlField = new ControlField("001", "I am data! (But not Data from Star Trek TNG)"); DataField dataField = new DataField("245"); DataField dataField2 = new DataField("521", new List<Subfield>(), ' ', '1'); target.Fields.Add(controlField); target.Fields.Add(dataField); target.Fields.Add(dataField2); { int expected = 3; int actual; actual = target.Fields.Count; Assert.AreEqual(expected, actual); } { Field expected = controlField; Field actual; actual = target.Fields[0]; Assert.AreSame(expected, actual); expected = dataField; actual = target.Fields[1]; Assert.AreSame(expected, actual); expected = dataField2; actual = target.Fields[2]; Assert.AreSame(expected, actual); } { List<Field> expected = new List<Field>(); expected.Add(controlField); expected.Add(dataField); expected.Add(dataField2); target.Fields = expected; List<Field> actual; actual = target.Fields; Assert.AreSame(expected, actual); } }
public void ToStringTest() { string tag = "001"; string data = " 2007032296"; ControlField target = new ControlField(tag, data); string expected = "001 2007032296"; string actual; actual = target.ToString(); Assert.AreEqual(expected, actual); }
public void ToRawTest() { string tag = "001"; string data = " 2007032296"; ControlField target = new ControlField(tag, data); string expected = " 2007032296" + FileMARC.END_OF_FIELD.ToString(); string actual; actual = target.ToRaw(); Assert.AreEqual(expected, actual); }
public void IsEmptyTest() { string tag = "001"; string data = " 2007032296"; ControlField target = new ControlField(tag, data); bool expected = false; bool actual; actual = target.IsEmpty(); Assert.AreEqual(expected, actual); target = new ControlField(tag, string.Empty); expected = true; actual = target.IsEmpty(); Assert.AreEqual(expected, actual); }
public void DataTest() { string tag = "001"; string data = " 2007032296"; ControlField target = new ControlField(tag, data); string expected = " 2011022800"; string actual; target.Data = expected; actual = target.Data; Assert.AreEqual(expected, actual); }
public void ControlFieldConstructorTest() { string tag = "001"; string data = " 2007032296"; ControlField target = new ControlField(tag, data); string expected = "001"; string actual = target.Tag; Assert.AreEqual(expected, actual); expected = " 2007032296"; actual = target.Data; Assert.AreEqual(expected, actual); }
internal virtual Field CreateControlField() { Field target = new ControlField("001", " 2007032296"); return target; }