public void CodeSyntax_XElementBuilderOfT_MultipleProps() { var props = new Dictionary<string, string> { { "FirstName", "Peter" }, { "LastName", "Åslund" }, }; var builder = new XElementBuilder<DocumentElement>(); builder.SetAttribute("version", "1.0"); foreach (var prop in props) { builder.AppendChild( new XElementBuilder<PropertyElement>() .SetAttribute("name", prop.Key) .SetAttribute("value", prop.Value) .Create() ); } var doc = builder.Create(); Assert.IsNotNull(doc); Assert.AreEqual(DocumentElement.TAGNAME, doc.Name.ToString()); Assert.AreEqual(props.Count, doc.Properties.Count()); foreach (var prop in props) { var propertyElement = doc.Properties[prop.Key]; Assert.IsNotNull(propertyElement); Assert.AreEqual(PropertyElement.TAGNAME, propertyElement.Name.ToString()); Assert.AreEqual(prop.Key, propertyElement.PropertyName); Assert.AreEqual(prop.Value, propertyElement.PropertyValue); } }
public void CodeSyntax_XElementBuilderOfT() { var builder = new XElementBuilder<DocumentElement>(); var doc = builder .SetAttribute("version", "1.0") .AppendChild( new XElementBuilder<PropertyElement>() .SetAttribute("name", "FirstName") .SetAttribute("value", "Peter") .Create() ) .Create(); Assert.IsNotNull(doc); Assert.AreEqual(DocumentElement.TAGNAME, doc.Name.ToString()); Assert.AreEqual(1, doc.Properties.Count()); var propertyElement = doc.Properties.Values.First(); Assert.AreEqual(PropertyElement.TAGNAME, propertyElement.Name.ToString()); Assert.AreEqual("FirstName", propertyElement.PropertyName); Assert.AreEqual("Peter", propertyElement.PropertyValue); }