Ejemplo n.º 1
0
        static void AssertDataFieldEquals(IVariableField vf, String tag, char ind1, char ind2, params string[] subfieldsAndValues)
        {
            var field = (IDataField)vf;

            Assert.AreEqual(tag, field.Tag, "tag");
            Assert.AreEqual(ind1, field.Indicator1, "Indicator 1");
            Assert.AreEqual(ind2, field.Indicator2, "Indicator 2");
            var subfields = field.GetSubfields();
            var it        = subfields.GetEnumerator();

            for (int i = 0; i < subfieldsAndValues.Length; i++)
            {
                var expectedCode  = subfieldsAndValues[i++];
                var expectedValue = subfieldsAndValues[i];
                if (!it.MoveNext())
                {
                    Assert.Fail("not enough subfields - expecting $" + expectedCode + " = " + expectedValue);
                }

                var sf = it.Current;
                Assert.AreEqual(sf.Code, expectedCode[0], "subfieldCode");
                Assert.AreEqual(expectedValue, sf.Data, "subfield value (" + tag + " $" + expectedCode + ") ");
            }
            if (it.MoveNext())
            {
                Assert.Fail("Too many subfields for " + tag + " - first unexpected is " + it.Current);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds a <code>VariableField</code> being a <code>ControlField</code>
        /// or <code>DataField</code>.
        /// If the <code>VariableField</code> is a control number field (001) and
        /// the record already has a control number field, the field is replaced with
        /// the new instance.
        /// </summary>
        /// <param name="field"></param>
        public virtual void AddVariableField(IVariableField field)
        {
            var tag = field.Tag;

            if (field is IControlField)
            {
                var controlField = (IControlField)field;
                if (Verifier.IsControlNumberField(tag))
                {
                    if (Verifier.HasControlNumberField(_controlFields))
                    {
                        _controlFields[0] = controlField;
                    }
                    else
                    {
                        _controlFields.Insert(0, controlField);
                    }
                }
                else
                {
                    _controlFields.Add(controlField);
                }
            }
            else
            {
                _dataFields.Add((IDataField)field);
            }
        }
Ejemplo n.º 3
0
        public override void AddVariableField(IVariableField field)
        {
            if (field is IControlField)
            {
                var controlField = (IControlField)field;
                var tag          = controlField.Tag;
                if (Verifier.IsControlNumberField(tag))
                {
                    if (Verifier.HasControlNumberField(GetControlFields()))
                    {
                        ControlFields[0] = controlField;
                    }
                    else
                    {
                        ControlFields.Insert(0, controlField);
                    }

                    ControlFields.Sort();
                }
                else if (Verifier.IsControlField(tag))
                {
                    ControlFields.Add(controlField);
                    ControlFields.Sort();
                }
            }
            else
            {
                DataFields.Add((IDataField)field);
                DataFields.Sort();
            }
        }
Ejemplo n.º 4
0
        public virtual void RemoveVariableField(IVariableField field)
        {
            var tag = field.Tag;

            if (Verifier.IsControlField(tag))
            {
                _controlFields.Remove(field as IControlField);
            }
            else
            {
                _dataFields.Remove(field as IDataField);
            }
        }
Ejemplo n.º 5
0
 public bool ValidateVariableField(IVariableField field)
 {
     return(field.Tag != null);
 }
Ejemplo n.º 6
0
        static void AssertControlFieldInRecordEquals(String tag, String expected, IVariableField field)
        {
            IControlField tmp = (IControlField)field;

            Assert.AreEqual(expected, tmp.Data, "Control field mismatch for tag " + tag);
        }
Ejemplo n.º 7
0
 public virtual int CompareTo(IVariableField other)
 {
     return(Tag.CompareTo(other.Tag));
 }