public void Clear_clears_items() { var w = new CollectionWrapper<String, Object>(CreateList()); w.Clear(); Assert.AreEqual(0, w.Count); }
private static CollectionWrapper GoGetThem(CollectionWrapper result, XmlNode region, string nameAtt, string valueAtt) { if (region.Attributes != null && region.Attributes.Count != 0) { if (region.Attributes.Count != 1 || region.Attributes[0].Name != "xmlns") { throw new ConfigurationException("Unknown attribute", region); } } XmlNode keyNode; XmlNode valueNode; XmlNodeList childs = region.ChildNodes; foreach (XmlNode node in childs) { XmlNodeType ntype = node.NodeType; if (ntype == XmlNodeType.Whitespace || ntype == XmlNodeType.Comment) { continue; } if (ntype != XmlNodeType.Element) { throw new ConfigurationException("Only XmlElement allowed", node); } string nodeName = node.Name; if (nodeName == "clear") { if (node.Attributes != null && node.Attributes.Count != 0) { throw new ConfigurationException("Unknown attribute", node); } result.Clear(); } else if (nodeName == "remove") { keyNode = null; if (node.Attributes != null) { keyNode = node.Attributes.RemoveNamedItem(nameAtt); } if (keyNode == null) { throw new ConfigurationException("Required attribute not found", node); } if (keyNode.Value == String.Empty) { throw new ConfigurationException("Required attribute is empty", node); } if (node.Attributes.Count != 0) { throw new ConfigurationException("Unknown attribute", node); } result.Remove(keyNode.Value); } else if (nodeName == "add") { keyNode = null; if (node.Attributes != null) { keyNode = node.Attributes.RemoveNamedItem(nameAtt); } if (keyNode == null) { throw new ConfigurationException("Required attribute not found", node); } if (keyNode.Value == String.Empty) { throw new ConfigurationException("Required attribute is empty", node); } valueNode = node.Attributes.RemoveNamedItem(valueAtt); if (valueNode == null) { throw new ConfigurationException("Required attribute not found", node); } if (node.Attributes.Count != 0) { throw new ConfigurationException("Unknown attribute", node); } result [keyNode.Value] = valueNode.Value; } else { throw new ConfigurationException("Unknown element", node); } } return(result); }
private static CollectionWrapper GoGetThem (CollectionWrapper result, XmlNode region, string nameAtt, string valueAtt) { if (region.Attributes != null && region.Attributes.Count != 0) { if (region.Attributes.Count != 1 || region.Attributes[0].Name != "xmlns") { throw new ConfigurationException ("Unknown attribute", region); } } XmlNode keyNode; XmlNode valueNode; XmlNodeList childs = region.ChildNodes; foreach (XmlNode node in childs) { XmlNodeType ntype = node.NodeType; if (ntype == XmlNodeType.Whitespace || ntype == XmlNodeType.Comment) continue; if (ntype != XmlNodeType.Element) throw new ConfigurationException ("Only XmlElement allowed", node); string nodeName = node.Name; if (nodeName == "clear") { if (node.Attributes != null && node.Attributes.Count != 0) throw new ConfigurationException ("Unknown attribute", node); result.Clear (); } else if (nodeName == "remove") { keyNode = null; if (node.Attributes != null) keyNode = node.Attributes.RemoveNamedItem (nameAtt); if (keyNode == null) throw new ConfigurationException ("Required attribute not found", node); if (keyNode.Value == String.Empty) throw new ConfigurationException ("Required attribute is empty", node); if (node.Attributes.Count != 0) throw new ConfigurationException ("Unknown attribute", node); result.Remove (keyNode.Value); } else if (nodeName == "add") { keyNode = null; if (node.Attributes != null) keyNode = node.Attributes.RemoveNamedItem (nameAtt); if (keyNode == null) throw new ConfigurationException ("Required attribute not found", node); if (keyNode.Value == String.Empty) throw new ConfigurationException ("Required attribute is empty", node); valueNode = node.Attributes.RemoveNamedItem (valueAtt); if (valueNode == null) throw new ConfigurationException ("Required attribute not found", node); if (node.Attributes.Count != 0) throw new ConfigurationException ("Unknown attribute", node); result [keyNode.Value] = valueNode.Value; } else { throw new ConfigurationException ("Unknown element", node); } } return result; }