/// <summary> /// Constructs the diffing engine. /// </summary> /// <param name="expected">The expected object.</param> /// <param name="actual">The actual object.</param> /// <param name="path">The current path of the parent node.</param> /// <param name="pathExpected">The path of the parent node of the expected collection.</param> /// <param name="options">Equality options.</param> /// <param name="itemType">A type of the diffed items.</param> public DiffEngineForOrderedItems(TCollection expected, TCollection actual, IXmlPathStrict path, IXmlPathStrict pathExpected, Options options, OrderedItemType itemType) { if (expected == null) { throw new ArgumentNullException("expected"); } if (actual == null) { throw new ArgumentNullException("actual"); } if (path == null) { throw new ArgumentNullException("path"); } if (pathExpected == null) { throw new ArgumentNullException("pathExpected"); } this.expected = expected; this.actual = actual; this.path = path; this.pathExpected = pathExpected; this.options = options; this.itemType = itemType; }
/// <inheritdoc /> public DiffSet Diff(NodeAttribute expected, IXmlPathStrict path, IXmlPathStrict pathExpected, Options options) { if (expected == null) { throw new ArgumentNullException("expected"); } if (path == null) { throw new ArgumentNullException("path"); } if (pathExpected == null) { throw new ArgumentNullException("pathExpected"); } var builder = new DiffSetBuilder(); if (!AreNamesEqual(expected.Name, options)) { builder.Add(new Diff(DiffType.UnexpectedAttribute, path.Attribute(index), DiffTargets.Actual)); } else if (!value.Equals(expected.Value, GetComparisonTypeForValue(options))) { builder.Add(new Diff(DiffType.MismatchedAttribute, path.Attribute(index), DiffTargets.Both)); } return(builder.ToDiffSet()); }
/// <inheritdoc /> public DiffSet Diff(NodeElement expected, IXmlPathStrict path, IXmlPathStrict pathExpected, Options options) { if (expected == null) { throw new ArgumentNullException("expected"); } if (path == null) { throw new ArgumentNullException("path"); } if (pathExpected == null) { throw new ArgumentNullException("pathExpected"); } if (!AreNamesEqual(expected.Name, options)) { return(new DiffSetBuilder() .Add(new Diff(DiffType.MismatchedElement, path.Element(Index), DiffTargets.Both)) .ToDiffSet()); } return(new DiffSetBuilder() .Add(attributes.Diff(expected.Attributes, path.Element(Index), pathExpected.Element(expected.Index), options)) .Add(Children.Diff(expected.Children, path.Element(Index), pathExpected.Element(expected.Index), options)) .ToDiffSet()); }
/// <summary> /// Constructs the diffing engine. /// </summary> /// <param name="expected">The expected object.</param> /// <param name="actual">The actual object.</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> public DiffEngineForUnorderedAttributes(NodeAttributeCollection expected, NodeAttributeCollection actual, IXmlPathStrict path, IXmlPathStrict pathExpected, Options options) { if (expected == null) { throw new ArgumentNullException("expected"); } if (actual == null) { throw new ArgumentNullException("actual"); } if (path == null) { throw new ArgumentNullException("path"); } if (pathExpected == null) { throw new ArgumentNullException("pathExpected"); } this.expected = expected; this.actual = actual; this.path = path; this.pathExpected = pathExpected; this.options = options; }
/// <summary> /// Constructs a node that extends the specified parent node by targetting an child element by its index. /// </summary> /// <param name="parent">The parent node to encapsulate.</param> /// <param name="index">The index of the child element.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="parent"/> is null.</exception> /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="index"/> is negative.</exception> public XmlPathStrictElement(IXmlPathStrict parent, int index) : base(parent, index) { if (index < 0) { throw new ArgumentOutOfRangeException("index"); } }
/// <summary> /// Constructs a node that extends the specified root node by targetting the declaration node. /// </summary> /// <param name="parent">The parent node to encapsulate.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="parent"/> is null.</exception> /// <exception cref="ArgumentException">Thrown if <paramref name="parent"/> is not the root.</exception> public XmlPathStrictDeclaration(IXmlPathStrict parent) : base(parent, -1) { if (!parent.IsEmpty) { throw new InvalidOperationException("A declaration node can only extend the root path."); } }
/// <summary> /// Formats a strict path into a human readable form, based on the contents of an existing XML fragment. /// </summary> /// <param name="path">The strict path to format.</param> /// <param name="fragment">The fragment used to format the path..</param> /// <param name="options">Rendering options.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="path"/>, or <paramref name="fragment"/> is null.</exception> public static string Run(IXmlPathStrict path, NodeFragment fragment, XmlPathRenderingOptions options) { var renderer = ((options & XmlPathRenderingOptions.UseIndentation) != 0) ? (XmlPathRenderer)new XmlPathRendererWithIndentation(path, fragment) : (XmlPathRenderer)new XmlPathRendererFlat(path, fragment); return renderer.RunImpl(); }
/// <summary> /// Constructs a node that extends the specified parent node with an additional level of depth. /// </summary> /// <param name="parent">The parent node to encapsulate.</param> /// <param name="index">The index of the inner attribute.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="parent"/> is null.</exception> protected XmlPathStrict(IXmlPathStrict parent, int index) { if (parent == null) throw new ArgumentNullException("parent"); this.parent = parent; this.index = index; }
/// <summary> /// Formats a strict path into a human readable form, based on the contents of an existing XML fragment. /// </summary> /// <param name="path">The strict path to format.</param> /// <param name="fragment">The fragment used to format the path..</param> /// <param name="options">Rendering options.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="path"/>, or <paramref name="fragment"/> is null.</exception> public static string Run(IXmlPathStrict path, NodeFragment fragment, XmlPathRenderingOptions options) { var renderer = ((options & XmlPathRenderingOptions.UseIndentation) != 0) ? (XmlPathRenderer) new XmlPathRendererWithIndentation(path, fragment) : (XmlPathRenderer) new XmlPathRendererFlat(path, fragment); return(renderer.RunImpl()); }
/// <summary> /// Constructs a node that extends the specified parent node by targetting an inner attribute by its index. /// </summary> /// <param name="parent">The parent node to encapsulate.</param> /// <param name="index">The index of the inner attribute.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="parent"/> is null.</exception> /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="index"/> is negative.</exception> public XmlPathStrictAttribute(IXmlPathStrict parent, int index) : base(parent, index) { if (index < 0) throw new ArgumentOutOfRangeException("index"); if (parent.IsEmpty) throw new InvalidOperationException("Cannot extend the root node with an attribute."); }
/// <summary> /// Makes a diffing engine for collections of elements. /// </summary> /// <param name="expected">The expected elements.</param> /// <param name="actual">The actual elements.</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<NodeCollection> ForElements(NodeCollection expected, NodeCollection actual, IXmlPathStrict path, IXmlPathStrict pathExpected, Options options) { if ((options & Options.IgnoreElementsOrder) != 0) { return new DiffEngineForUnorderedElements(expected, actual, path, pathExpected, options); } return new DiffEngineForOrderedItems<NodeCollection, INode>(expected, actual, path, pathExpected, options, OrderedItemType.Element); }
/// <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); }
protected XmlPathRenderer(IXmlPathStrict path, NodeFragment fragment) { if (path == null) throw new ArgumentNullException("path"); if (fragment == null) throw new ArgumentNullException("fragment"); this.rootPath = path; this.fragment = fragment; }
/// <summary> /// Constructs a node that extends the specified parent node with an additional level of depth. /// </summary> /// <param name="parent">The parent node to encapsulate.</param> /// <param name="index">The index of the inner attribute.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="parent"/> is null.</exception> protected XmlPathStrict(IXmlPathStrict parent, int index) { if (parent == null) { throw new ArgumentNullException("parent"); } this.parent = parent; this.index = index; }
/// <summary> /// Constructs a diff item. /// </summary> /// <param name="diffType">The type of the diff.</param> /// <param name="path">The path of the difference.</param> /// <param name="targets">Indicates which XML fragment is targeted by the diff.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="diffType"/> or <paramref name="path"/> is null.</exception> /// <exception cref="ArgumentException">Thrown if <paramref name="diffType"/> or <paramref name="path"/> is empty.</exception> public Diff(DiffType diffType, IXmlPathStrict path, DiffTargets targets) { if (diffType == null) throw new ArgumentNullException("diffType"); if (path == null) throw new ArgumentNullException("path"); this.diffType = diffType; this.path = path; this.targets = targets; }
/// <inheritdoc /> public override DiffSet Diff(INode expected, IXmlPathStrict path, IXmlPathStrict pathExpected, Options options) { var fragment = expected as NodeFragment; if (fragment == null) { throw new ArgumentException("Invalid XML fragment", "expected"); } return(Diff(fragment, path, pathExpected, options)); }
/// <summary> /// Constructs a node that extends the specified parent node by targetting an inner attribute by its index. /// </summary> /// <param name="parent">The parent node to encapsulate.</param> /// <param name="index">The index of the inner attribute.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="parent"/> is null.</exception> /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="index"/> is negative.</exception> public XmlPathStrictAttribute(IXmlPathStrict parent, int index) : base(parent, index) { if (index < 0) { throw new ArgumentOutOfRangeException("index"); } if (parent.IsEmpty) { throw new InvalidOperationException("Cannot extend the root node with an attribute."); } }
/// <inheritdoc /> public override DiffSet Diff(INode expected, IXmlPathStrict path, IXmlPathStrict pathExpected, Options options) { var expectedComment = expected as NodeComment; if (expectedComment != null) { return(Diff(expectedComment, path, pathExpected, options)); } return(new DiffSetBuilder() .Add(new Diff(DiffType.UnexpectedComment, path.Element(Index), DiffTargets.Actual)) .ToDiffSet()); }
/// <inheritdoc /> public DiffSet Diff(NodeDeclaration expected, IXmlPathStrict path, IXmlPathStrict pathExpected, Options options) { if (expected == null) { throw new ArgumentNullException("expected"); } if (path == null) { throw new ArgumentNullException("path"); } return(attributes.Diff(expected.Attributes, path, pathExpected, options)); }
private void ProcessPathNode(IXmlPathStrict path, int level) { var node = fragment.Find(path); if (node != null) { Aggregate(node, level); } if (path.Parent != null && !path.Parent.IsEmpty) { ProcessPathNode(path.Parent, level + 1); } }
protected XmlPathRenderer(IXmlPathStrict path, NodeFragment fragment) { if (path == null) { throw new ArgumentNullException("path"); } if (fragment == null) { throw new ArgumentNullException("fragment"); } this.rootPath = path; this.fragment = fragment; }
/// <summary> /// Constructs a diff item. /// </summary> /// <param name="diffType">The type of the diff.</param> /// <param name="path">The path of the difference.</param> /// <param name="targets">Indicates which XML fragment is targeted by the diff.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="diffType"/> or <paramref name="path"/> is null.</exception> /// <exception cref="ArgumentException">Thrown if <paramref name="diffType"/> or <paramref name="path"/> is empty.</exception> public Diff(DiffType diffType, IXmlPathStrict path, DiffTargets targets) { if (diffType == null) { throw new ArgumentNullException("diffType"); } if (path == null) { throw new ArgumentNullException("path"); } this.diffType = diffType; this.path = path; this.targets = targets; }
/// <inheritdoc /> public DiffSet Diff(NodeFragment expected, IXmlPathStrict path, IXmlPathStrict pathExpected, Options options) { if (expected == null) { throw new ArgumentNullException("expected"); } if (path == null) { throw new ArgumentNullException("path"); } return(new DiffSetBuilder() .Add(declaration.Diff(expected.Declaration, path.Declaration(), pathExpected.Declaration(), options)) .Add(Children.Diff(expected.Children, path, pathExpected, options)) .ToDiffSet()); }
/// <summary> /// Finds the node located at the specified path. /// </summary> /// <param name="path">The searched strict path.</param> /// <returns>The node found.</returns> /// <exception cref="ArgumentNullException">Thrown if <paramref name="path"/> is null.</exception> public INode Find(IXmlPathStrict path) { if (path == null) { throw new ArgumentNullException("path"); } INode current = this; var array = path.ToArray(); for (int i = 0; i < array.Length && current != null; i++) { current = array[i].FindInParent(current); } return(current); }
/// <inheritdoc /> public DiffSet Diff(NodeComment expected, IXmlPathStrict path, IXmlPathStrict pathExpected, Options options) { if (expected == null) { throw new ArgumentNullException("expected"); } if (path == null) { throw new ArgumentNullException("path"); } if (pathExpected == null) { throw new ArgumentNullException("pathExpected"); } if (((options & Options.IgnoreComments) != 0) || Text.Equals(expected.Text)) { return(DiffSet.Empty); } return(new DiffSetBuilder() .Add(new Diff(DiffType.MismatchedComment, path.Element(Index), DiffTargets.Both)) .ToDiffSet()); }
/// <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 XmlPathRendererFlat(IXmlPathStrict path, NodeFragment fragment) : base(path, fragment) { }
/// <inheritdoc /> public override DiffSet Diff(INode expected, IXmlPathStrict path, IXmlPathStrict pathExpected, Options options) { return(Diff((NodeDeclaration)expected, path, pathExpected, options)); }
public XmlPathRendererWithIndentation(IXmlPathStrict path, NodeFragment fragment) : base(path, fragment) { }
/// <summary> /// Constructs a node that extends the specified root node by targetting the declaration node. /// </summary> /// <param name="parent">The parent node to encapsulate.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="parent"/> is null.</exception> /// <exception cref="ArgumentException">Thrown if <paramref name="parent"/> is not the root.</exception> public XmlPathStrictDeclaration(IXmlPathStrict parent) : base(parent, -1) { if (!parent.IsEmpty) throw new InvalidOperationException("A declaration node can only extend the root path."); }
/// <summary> /// Constructs a node that extends the specified parent node by targetting an child element by its index. /// </summary> /// <param name="parent">The parent node to encapsulate.</param> /// <param name="index">The index of the child element.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="parent"/> is null.</exception> /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="index"/> is negative.</exception> public XmlPathStrictElement(IXmlPathStrict parent, int index) : base(parent, index) { if (index < 0) throw new ArgumentOutOfRangeException("index"); }
/// <inheritdoc /> public abstract DiffSet Diff(INode expected, IXmlPathStrict path, IXmlPathStrict pathExpected, Options options);
/// <summary> /// Makes a diffing engine for collections of elements. /// </summary> /// <param name="expected">The expected elements.</param> /// <param name="actual">The actual elements.</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 <NodeCollection> ForElements(NodeCollection expected, NodeCollection actual, IXmlPathStrict path, IXmlPathStrict pathExpected, Options options) { if ((options & Options.IgnoreElementsOrder) != 0) { return(new DiffEngineForUnorderedElements(expected, actual, path, pathExpected, options)); } return(new DiffEngineForOrderedItems <NodeCollection, INode>(expected, actual, path, pathExpected, options, OrderedItemType.Element)); }
/// <inheritdoc /> public DiffSet Diff(INode expected, IXmlPathStrict path, IXmlPathStrict pathExpected, Options options) { return(Diff((NodeAttribute)expected, path, pathExpected, options)); }
public IXmlPathStrict ExtendsPath(IXmlPathStrict path, int childIndex) { return(pathExtender(path, childIndex)); }
private void ProcessPathNode(IXmlPathStrict path, int level) { var node = fragment.Find(path); if (node != null) Aggregate(node, level); if (path.Parent != null && !path.Parent.IsEmpty) { ProcessPathNode(path.Parent, level + 1); } }
/// <inheritdoc /> public DiffSet Diff(NodeAttributeCollection expected, IXmlPathStrict path, IXmlPathStrict pathExpected, Options options) { return(DiffEngineFactory.ForAttributes(expected, this, path, pathExpected, options).Diff()); }