/// <summary> /// Makes a diffing engine for collections of attributes. /// </summary> /// <param name="expected">The expected attributes.</param> /// <param name="actual">The actual attributes.</param> /// <param name="path">The current path of the parent node.</param> /// <param name="pathExpected">The path of the parent node of the parent collection.</param> /// <param name="options">Equality options.</param> /// <returns>The resulting diffing engine.</returns> public static IDiffEngine<NodeAttributeCollection> ForAttributes(NodeAttributeCollection expected, NodeAttributeCollection actual, IXmlPathStrict path, IXmlPathStrict pathExpected, Options options) { if ((options & Options.IgnoreAttributesOrder) != 0) { return new DiffEngineForUnorderedAttributes(expected, actual, path, pathExpected, options); } return new DiffEngineForOrderedItems<NodeAttributeCollection, NodeAttribute>(expected, actual, path, pathExpected, options, OrderedItemType.Attribute); }
public void Constructs_ok() { var attribute1 = new Gallio.Common.Xml.NodeAttribute(123, "name1", "value1", 999); var attribute2 = new Gallio.Common.Xml.NodeAttribute(456, "name2", "value2", 999); var attribute3 = new Gallio.Common.Xml.NodeAttribute(789, "name3", "value3", 999); var array = new[] { attribute1, attribute2, attribute3 }; var collection = new NodeAttributeCollection(array); Assert.Count(3, collection); Assert.AreElementsSame(array, collection); }
/// <summary> /// Makes a diffing engine for collections of attributes. /// </summary> /// <param name="expected">The expected attributes.</param> /// <param name="actual">The actual attributes.</param> /// <param name="path">The current path of the parent node.</param> /// <param name="pathExpected">The path of the parent node of the parent collection.</param> /// <param name="options">Equality options.</param> /// <returns>The resulting diffing engine.</returns> public static IDiffEngine <NodeAttributeCollection> ForAttributes(NodeAttributeCollection expected, NodeAttributeCollection actual, IXmlPathStrict path, IXmlPathStrict pathExpected, Options options) { if ((options & Options.IgnoreAttributesOrder) != 0) { return(new DiffEngineForUnorderedAttributes(expected, actual, path, pathExpected, options)); } return(new DiffEngineForOrderedItems <NodeAttributeCollection, NodeAttribute>(expected, actual, path, pathExpected, options, OrderedItemType.Attribute)); }
private static NodeBuilder ParseElement(int index, XmlReader reader) { string name = reader.Name; var children = new List<NodeBuilder>(); var attributes = new NodeAttributeCollection(GetAttributes(reader)); int i = 0; if (!reader.IsEmptyElement) { while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.EndElement: return count => new NodeElement(index, count, name, attributes, children.ConvertAll(x => x(i))); case XmlNodeType.Text: { int current = i++; string text = reader.Value; children.Add(count => new NodeContent(current, count, text)); break; } case XmlNodeType.Element: children.Add(ParseElement(i++, reader)); break; case XmlNodeType.Comment: { int current = i++; string text = reader.Value; children.Add(count => new NodeComment(current, count, text)); break; } default: break; } } } return count => new NodeElement(index, count, name, attributes, children.ConvertAll(x => x(i))); }
private NodeFragment RunImpl(Options options) { INode root = null; var declarationAttributes = NodeAttributeCollection.Empty; var settings = new XmlReaderSettings() { IgnoreComments = ((options & Options.IgnoreComments) != 0), IgnoreWhitespace = true }; using (var reader = XmlReader.Create(new StringReader(xml), settings)) { while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: var rootBuilder = ParseElement(0, reader); root = rootBuilder(1); break; case XmlNodeType.XmlDeclaration: declarationAttributes = new NodeAttributeCollection(GetAttributes(reader)); break; default: break; } } } if (root == null) throw new ArgumentException("The specified XML fragment does not have any root element.", "xml"); return new NodeFragment(new NodeDeclaration(declarationAttributes), root); }