public void Test_FromXml_Append_Decimals_M7() { XmlDocument doc = new XmlDocument(); XmlElement elem = doc.CreateElement( "test" ); doc.AppendChild( elem ); Precision pp = new Precision( Precision.PrecisionTypeCode.Decimals, -7 ); XmlAttribute attr = pp.CreateAttribute( doc ); Precision p = null; ArrayList errors = new ArrayList(); Assert.IsTrue( Precision.TryCreateFromXml( attr, out p, ref errors ), "precision not created" ); Assert.IsTrue( p.ValueEquals( pp ), "xml precision different from the real deal" ); }
public void Test_Append_DecimalINF() { XmlDocument doc = new XmlDocument(); XmlElement elem = doc.CreateElement( "test" ); doc.AppendChild( elem ); Precision pp = new Precision( Precision.PrecisionTypeCode.Decimals ); elem.Attributes.Append( pp.CreateAttribute( doc ) ); string expectedXML = @"<?xml version=""1.0"" encoding=""utf-16""?> <test decimals=""INF"" />"; System.IO.StringWriter writer = new System.IO.StringWriter(); doc.Save( writer ); Assert.AreEqual( expectedXML, writer.ToString() ); }
/// <summary> /// Appends unit nodes to a parameter supplied root element if they do not exist in <see cref="xDoc"/>. /// Sets the "unitRef" attribute to reflect the unit id /// of a parameter-supplied <see cref="UnitProperty"/>. /// </summary> /// <param name="root">The document-level root element to which elements will be appended.</param> /// <param name="elem">The element whose attributes are to be set.</param> /// <param name="errors">A collection of <see cref="String"/> objects to which method /// will append any errors.</param> /// <param name="presProp">A <see cref="Precision"/> from which precision attributes will be created.</param> /// <param name="unit">A <see cref="UnitProperty"/> from which unit elements will be created.</param> protected void AppendUnitInfo(XmlElement root, XmlElement elem, UnitProperty unit, Precision presProp, ArrayList errors) { elem.SetAttribute( UNIT_REF, unit.UnitID ); if ( presProp != null ) { elem.Attributes.Append( presProp.CreateAttribute( xDoc ) ); } string mergeKey = mergeDocs ? @"//link2:" : @"//"; if ( this.xDoc.SelectSingleNode( string.Format( mergeKey + "unit[@id=\"{0}\"]", unit.UnitID ), theManager ) == null ) { XmlElement unitNode = null; if ( mergeDocs ) { units.Add( unit ); if ( unit.CreateElementWithNamespaces( xDoc, root, errors, out unitNode, this.writeComments ) ) { root.InsertAfter( unitNode, unitComment ); } } else { if ( unit.CreateElement( xDoc, root, errors, out unitNode, this.writeComments ) ) { root.InsertAfter( unitNode, unitComment ); } } } }