/// <summary> /// Returns the diff as an assertion failure. /// </summary> /// <param name="expected">The expected fragment used to format the diff.</param> /// <param name="actual">The actual fragment used to format the diff.</param> /// <returns>The resulting assertion failure.</returns> /// <exception cref="ArgumentNullException">Thrown if <paramref name="expected"/> or <paramref name="actual"/> is null.</exception> public AssertionFailure ToAssertionFailure(NodeFragment expected, NodeFragment actual) { bool showActual = ((targets & DiffTargets.Actual) != 0); bool showExpected = ((targets & DiffTargets.Expected) != 0); var builder = new AssertionFailureBuilder(diffType.Description, new NullFormatter()); const XmlPathRenderingOptions options = XmlPathRenderingOptions.UseIndentation; if (showActual && showExpected) { var actualFormatted = XmlPathRenderer.Run(path, actual, options); var expectedFormatted = XmlPathRenderer.Run(path, expected, options); builder.AddRawExpectedAndActualValuesWithDiffs(expectedFormatted, actualFormatted); } else if (showActual) { var actualFormatted = XmlPathRenderer.Run(path, actual, options); builder.AddRawActualValue(actualFormatted); } else if (showExpected) { var expectedFormatted = XmlPathRenderer.Run(path, expected, options); builder.AddRawExpectedValue(expectedFormatted); } return(builder.ToAssertionFailure()); }
public void Constructs_empty() { var mockRoot = MockRepository.GenerateStub<INode>(); var declaration = new NodeDeclaration(NodeAttributeCollection.Empty); var document = new NodeFragment(declaration, mockRoot); Assert.AreSame(declaration, document.Declaration); }
/// <summary> /// Returns the diff items as an enumeration of assertion failures. /// </summary> /// <param name="expected">The expected fragment used to format the diff.</param> /// <param name="actual">The actual fragment used to format the diff.</param> /// <returns>The resulting enumeration of assertion failures.</returns> /// <exception cref="ArgumentNullException">Thrown if <paramref name="expected"/> or <paramref name="actual"/> is null.</exception> public IEnumerable <AssertionFailure> ToAssertionFailures(NodeFragment expected, NodeFragment actual) { foreach (Diff diff in diffs) { yield return(diff.ToAssertionFailure(expected, actual)); } }
public void Parse() { NodeFragment fragment = Parser.Run(sample, Options.None); // Level 0. var children = fragment.Children.ToList(); Assert.Count(1, children); Assert.IsInstanceOfType <NodeElement>(children[0]); Assert.AreEqual("Root", ((NodeElement)children[0]).Name); Assert.IsTrue(children[0].IsFirst); Assert.IsTrue(children[0].IsLast); Assert.IsEmpty(((NodeElement)children[0]).Attributes); // Level 1. children = children[0].Children.ToList(); Assert.AreEqual(2, children.Count); Assert.IsInstanceOfType <NodeComment>(children[0]); Assert.AreEqual(" Some comment ", ((NodeComment)children[0]).Text); Assert.IsTrue(children[0].IsFirst); Assert.IsFalse(children[0].IsLast); Assert.IsInstanceOfType <NodeElement>(children[1]); Assert.AreEqual("Parent", ((NodeElement)children[1]).Name); Assert.IsFalse(children[1].IsFirst); Assert.IsTrue(children[1].IsLast); Assert.IsEmpty(((NodeElement)children[1]).Attributes); // Level 3 - Child 1. children = children[1].Children.ToList(); Assert.Count(2, children); Assert.IsInstanceOfType <NodeElement>(children[0]); Assert.AreEqual("Child", ((NodeElement)children[0]).Name); Assert.IsTrue(children[0].IsFirst); Assert.IsFalse(children[0].IsLast); Assert.Count(1, ((NodeElement)children[0]).Attributes); Assert.AreEqual("id", ((NodeElement)children[0]).Attributes[0].Name); Assert.AreEqual("123", ((NodeElement)children[0]).Attributes[0].Value); Assert.IsTrue(((NodeElement)children[0]).Attributes[0].IsFirst); Assert.IsTrue(((NodeElement)children[0]).Attributes[0].IsLast); Assert.IsEmpty(((NodeElement)children[0]).Children); // Level 3 - Child 2. Assert.IsInstanceOfType <NodeElement>(children[1]); Assert.AreEqual("Child", ((NodeElement)children[1]).Name); Assert.Count(1, ((NodeElement)children[1]).Attributes); Assert.IsFalse(children[1].IsFirst); Assert.IsTrue(children[1].IsLast); Assert.AreEqual("id", ((NodeElement)children[1]).Attributes[0].Name); Assert.AreEqual("456", ((NodeElement)children[1]).Attributes[0].Value); Assert.IsTrue(((NodeElement)children[1]).Attributes[0].IsFirst); Assert.IsTrue(((NodeElement)children[1]).Attributes[0].IsLast); // Level 4. children = children[1].Children.ToList(); Assert.IsInstanceOfType <NodeContent>(children[0]); Assert.AreEqual("Data", ((NodeContent)children[0]).Text); Assert.IsTrue(children[0].IsFirst); Assert.IsTrue(children[0].IsLast); }
public void Constructs_empty() { var mockRoot = MockRepository.GenerateStub <INode>(); var declaration = new NodeDeclaration(NodeAttributeCollection.Empty); var document = new NodeFragment(declaration, mockRoot); Assert.AreSame(declaration, document.Declaration); }
/// <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> /// 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(); }
public void Format_path(string input, string expected, [TextData(ResourcePath = "SolarSystem.xml")] string xml) { NodeFragment fragment = Parser.Run(xml, Options.None); var path = XmlPathRoot.Strict.Parse(input); var actual = XmlPathRenderer.Run(path, fragment, XmlPathRenderingOptions.None); Assert.AreEqual(expected, actual); }
/// <inheritdoc/> public override string ToString(NodeFragment fragment) { if (fragment == null) { throw new ArgumentNullException("fragment"); } throw new NotImplementedException(); }
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; }
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; }
public XmlPathRendererWithIndentation(IXmlPathStrict path, NodeFragment fragment) : base(path, fragment) { }
public XmlPathRendererFlat(IXmlPathStrict path, NodeFragment fragment) : base(path, fragment) { }
/// <inheritdoc/> public abstract string ToString(NodeFragment fragment);
/// <inheritdoc/> public override string ToString(NodeFragment fragment) { if (fragment == null) throw new ArgumentNullException("fragment"); throw new NotImplementedException(); }
/// <summary> /// Returns the diff as an assertion failure. /// </summary> /// <param name="expected">The expected fragment used to format the diff.</param> /// <param name="actual">The actual fragment used to format the diff.</param> /// <returns>The resulting assertion failure.</returns> /// <exception cref="ArgumentNullException">Thrown if <paramref name="expected"/> or <paramref name="actual"/> is null.</exception> public AssertionFailure ToAssertionFailure(NodeFragment expected, NodeFragment actual) { bool showActual = ((targets & DiffTargets.Actual) != 0); bool showExpected = ((targets & DiffTargets.Expected) != 0); var builder = new AssertionFailureBuilder(diffType.Description, new NullFormatter()); const XmlPathRenderingOptions options = XmlPathRenderingOptions.UseIndentation; if (showActual && showExpected) { var actualFormatted = XmlPathRenderer.Run(path, actual, options); var expectedFormatted = XmlPathRenderer.Run(path, expected, options); builder.AddRawExpectedAndActualValuesWithDiffs(expectedFormatted, actualFormatted); } else if (showActual) { var actualFormatted = XmlPathRenderer.Run(path, actual, options); builder.AddRawActualValue(actualFormatted); } else if (showExpected) { var expectedFormatted = XmlPathRenderer.Run(path, expected, options); builder.AddRawExpectedValue(expectedFormatted); } return builder.ToAssertionFailure(); }