public void CamlTag_CreatesTagWithInnerValue() { Expected = "<Tag>x</Tag>"; CamlTag tag = new CamlTag("Tag") {InnerText = "x"}; string caml = tag.ToString(); Assert.That(caml, Is.EqualTo(Expected)); }
public void CamlTag_CreatesSelfClosingTagWithSpecifiedName() { Expected = "<Tag />"; CamlTag tag = new CamlTag("Tag"); string caml = tag.ToString(); Assert.That(caml, Is.EqualTo(Expected)); }
public void CamlTag_CreatesTagWithAttribute() { Expected = "<Tag Attr='a1' />"; CamlTag tag = new CamlTag("Tag"); tag.MergeAttribute("Attr", "a1"); string caml = tag.ToString(); Assert.That(caml, Is.EqualTo(Expected)); }
public void CamlTag_CreatesTagWithInnerTag() { Expected = "<Tag><Tag2 /></Tag>"; CamlTag tag = new CamlTag("Tag"); CamlTag tag2 = new CamlTag("Tag2"); tag.InnerText = tag2.ToString(); string caml = tag.ToString(); Assert.That(caml, Is.EqualTo(Expected)); }
public void CamlTag_CreatesTagWithValueAndAttributes() { Expected = "<Tag Attr='a1' Xy='zz'>x</Tag>"; CamlTag tag = new CamlTag("Tag"); tag.MergeAttribute("Attr", "a1"); tag.MergeAttribute("Xy", "zz"); tag.InnerText = "x"; string caml = tag.ToString(); Assert.That(caml, Is.EqualTo(Expected)); }
/// <summary> /// Used internaly to get CAML markup from elements. /// </summary> public virtual string GetCaml() { CamlTag tag = new CamlTag(Tag.ToString()); PropertyInfo[] properties = GetType().GetProperties(); foreach (PropertyInfo property in properties) { CQAttributeAttribute attribute = (CQAttributeAttribute)property.GetCustomAttributes(typeof(CQAttributeAttribute), true).FirstOrDefault(); if (attribute == null) continue; string name = attribute.Name ?? property.Name; object value = property.GetValue(this, null); if (value != null) { switch (attribute.Capitalization) { case CQAttributeCapitalization.UpperCase: value = value.ToString().ToUpperInvariant(); break; case CQAttributeCapitalization.LowerCase: value = value.ToString().ToLowerInvariant(); break; } } tag.MergeAttribute(name, value); } if (_elements.Count != 0) { StringBuilder builder = new StringBuilder(); foreach (ICQElement element in _elements) { builder.Append(element.GetCaml()); } tag.InnerText = builder.ToString(); } else tag.InnerText = InnerText; return tag.ToString(); }