/// <inheritdoc/> public IXmlPathLoose Trail() { IXmlPathLoose[] all = AsArray(); IXmlPathLoose path = XmlPathLooseOpenElement.Root; for (int i = 1; i < all.Length; i++) { path = all[i].Copy(path); } return(path); }
/// <summary> /// Returns the number of times the searched node was found at the specified path. /// </summary> /// <param name="searchedPath">The path of the searched node.</param> /// <param name="expectedValue">The expected value found in the searched node, or null if the value must be ignored.</param> /// <param name="options">Options for the search.</param> /// <returns>The number of matching items found; zero if not found.</returns> /// <exception cref="ArgumentNullException">Thrown if <paramref name="searchedPath"/> is null.</exception> public int CountAt(IXmlPathLoose searchedPath, string expectedValue, Options options) { if (searchedPath == null) { throw new ArgumentNullException("searchedPath"); } int count = 0; foreach (INode node in nodes) { count += node.CountAt(searchedPath, expectedValue, options); } return(count); }
/// <inheritdoc /> public override int CountAt(IXmlPathLoose searchedPath, string expectedValue, Options options) { if (searchedPath == null) { throw new ArgumentNullException("searchedPath"); } if (searchedPath.IsEmpty) { return(0); } IXmlPathLoose[] array = searchedPath.AsArray(); var head = array[0] as XmlPathLooseOpenElement; if (head == null || !AreNamesEqual(head.Name, options)) { return(0); } IXmlPathLoose trail = searchedPath.Trail(); if (!trail.IsEmpty) { return(Attributes.CountAt(trail, expectedValue, options) + Children.CountAt(trail, expectedValue, options)); } if (expectedValue == null) { return(1); } if (Children.Count != 1) { return(0); } var content = Children[0] as NodeContent; return(((content != null) && content.AreValuesEqual(expectedValue, options)) ? 1 : 0); }
/// <inheritdoc /> public int CountAt(IXmlPathLoose searchedPath, string expectedValue, Options options) { if (searchedPath == null) { throw new ArgumentNullException("searchedPath"); } if (searchedPath.IsEmpty) { return(0); } IXmlPathLoose[] array = searchedPath.AsArray(); var head = array[0] as XmlPathLooseClosedAttribute; if (head == null || !AreNamesEqual(head.Name, options) || ((expectedValue != null) && !AreValuesEqual(expectedValue, options))) { return(0); } return(1); }
/// <summary> /// Asserts that the XML fragment contains the searched element or attribute. /// </summary> /// <remarks> /// <para> /// Options not related to the name case of elements and attributes are going to be ignored. /// </para> /// </remarks> /// <param name="actualXmlReader">A reader to get the actual XML fragment.</param> /// <param name="searchedPath">The path of the searched element or attribute in the XML fragment.</param> /// <param name="options">Options for the search.</param> /// <param name="messageFormat">The custom assertion message format, or null if none.</param> /// <param name="messageArgs">The custom assertion message arguments, or null if none.</param> /// <exception cref="AssertionException">Thrown if the verification failed unless the current <see cref="AssertionContext.AssertionFailureBehavior" /> indicates otherwise.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="actualXmlReader"/>, <paramref name="searchedPath"/>, or <paramref name="options"/> is null.</exception> public static void Exists(TextReader actualXmlReader, IXmlPathLoose searchedPath, XmlOptions options, string messageFormat, params object[] messageArgs) { Exists(actualXmlReader, searchedPath, options, null, messageFormat, messageArgs); }
/// <summary> /// Asserts that the XML fragment contains the searched element or attribute. /// </summary> /// <remarks> /// <para> /// Options not related to the name case of elements and attributes are going to be ignored. /// </para> /// </remarks> /// <param name="actualXmlReader">A reader to get the actual XML fragment.</param> /// <param name="searchedPath">The path of the searched element or attribute in the XML fragment.</param> /// <param name="options">Options for the search.</param> /// <exception cref="AssertionException">Thrown if the verification failed unless the current <see cref="AssertionContext.AssertionFailureBehavior" /> indicates otherwise.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="actualXmlReader"/>, <paramref name="searchedPath"/>, or <paramref name="options"/> is null.</exception> public static void Exists(TextReader actualXmlReader, IXmlPathLoose searchedPath, XmlOptions options) { Exists(actualXmlReader, searchedPath, options, null, null, null); }
/// <inheritdoc/> public override IXmlPathLoose Copy(IXmlPathLoose parent) { return(new XmlPathLooseClosedAttribute((IXmlPathLooseClosed)parent, name)); }
/// <summary> /// Asserts that the XML fragment contains the searched element or attribute, that it has the expected value, and that this element or attribute is unique in the entire fragment. /// </summary> /// <remarks> /// <para> /// If <paramref name="expectedValue"/> is set to <c>null</c>, the assertion behaves like <see cref="Assert.Xml.Exists(string, IXmlPathLoose, XmlOptions)"/>. /// </para> /// </remarks> /// <param name="actualXml">The actual XML fragment.</param> /// <param name="searchedPath">The path of the searched element or attribute in the XML fragment.</param> /// <param name="expectedValue">The expected value of the searched item (element or attribute).</param> /// <param name="options">Options for the search.</param> /// <exception cref="AssertionException">Thrown if the verification failed unless the current <see cref="AssertionContext.AssertionFailureBehavior" /> indicates otherwise.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="actualXml"/>, <paramref name="searchedPath"/>, or <paramref name="options"/> is null.</exception> public static void IsUnique(string actualXml, IXmlPathLoose searchedPath, string expectedValue, XmlOptions options) { IsUnique(actualXml, searchedPath, options, expectedValue, null, null); }
/// <summary> /// Asserts that the XML fragment contains the searched element or attribute, that it has the expected value, and that this element or attribute is unique in the entire fragment. /// </summary> /// <remarks> /// <para> /// If <paramref name="expectedValue"/> is set to <c>null</c>, the assertion behaves like <see cref="Assert.Xml.Exists(TextReader, IXmlPathLoose, XmlOptions)"/>. /// </para> /// </remarks> /// <param name="actualXmlReader">A reader to get the actual XML fragment.</param> /// <param name="searchedPath">The path of the searched element or attribute in the XML fragment.</param> /// <param name="options">Options for the search.</param> /// <param name="expectedValue">The expected value of the searched item (element or attribute).</param> /// <exception cref="AssertionException">Thrown if the verification failed unless the current <see cref="AssertionContext.AssertionFailureBehavior" /> indicates otherwise.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="actualXmlReader"/>, <paramref name="searchedPath"/>, or <paramref name="options"/> is null.</exception> public static void IsUnique(TextReader actualXmlReader, IXmlPathLoose searchedPath, XmlOptions options, string expectedValue) { IsUnique(actualXmlReader, searchedPath, options, expectedValue, null, null); }
/// <summary> /// Asserts that the XML fragment contains the searched element or attribute, and that this element or attribute is unique in the entire fragment. /// </summary> /// <remarks> /// <para> /// Options not related to the name case of elements and attributes are going to be ignored. /// </para> /// </remarks> /// <param name="actualXmlReader">A reader to get the actual XML fragment.</param> /// <param name="searchedPath">The path of the searched element or attribute in the XML fragment.</param> /// <param name="options">Options for the search.</param> /// <exception cref="AssertionException">Thrown if the verification failed unless the current <see cref="AssertionContext.AssertionFailureBehavior" /> indicates otherwise.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="actualXmlReader"/>, <paramref name="searchedPath"/>, or <paramref name="options"/> is null.</exception> public static void IsUnique(TextReader actualXmlReader, IXmlPathLoose searchedPath, XmlOptions options) { IsUnique(actualXmlReader, searchedPath, options, null, null, null); }
/// <inheritdoc/> public override IXmlPathLoose Copy(IXmlPathLoose parent) { return new XmlPathLooseOpenElement((IXmlPathLooseOpen)parent, name); }
/// <inheritdoc /> public override int CountAt(IXmlPathLoose searchedPath, string expectedValue, Options options) { return(Children.CountAt(searchedPath, expectedValue, options)); }
/// <inheritdoc /> public virtual int CountAt(IXmlPathLoose searchedPath, string expectedValue, Options options) { return(0); }
/// <inheritdoc /> public virtual int CountAt(IXmlPathLoose searchedPath, string expectedValue, Options options) { return 0; }
/// <summary> /// Asserts that the XML fragment contains the searched element or attribute. /// </summary> /// <exception cref="ArgumentNullException">Thrown if <paramref name="actualXml"/>, <paramref name="searchedPath"/>, or <paramref name="options"/> is null.</exception> /// <remarks> /// <para> /// Options not related to the name case of elements and attributes are going to be ignored. /// </para> /// </remarks> /// <param name="actualXml">The actual XML fragment.</param> /// <param name="searchedPath">The path of the searched element or attribute in the XML fragment.</param> /// <param name="options">Options for the search.</param> /// <exception cref="AssertionException">Thrown if the verification failed unless the current <see cref="AssertionContext.AssertionFailureBehavior" /> indicates otherwise.</exception> public static void Exists(string actualXml, IXmlPathLoose searchedPath, XmlOptions options) { Exists(actualXml, searchedPath, options, null, null, null); }
/// <summary> /// Asserts that the XML fragment contains the searched element or attribute, and that it has the expected value. /// </summary> /// <param name="actualXml">The actual XML fragment.</param> /// <param name="searchedPath">The path of the searched element or attribute in the XML fragment.</param> /// <param name="options">Options for the search.</param> /// <param name="expectedValue">The expected value of the searched item (element or attribute).</param> /// <exception cref="AssertionException">Thrown if the verification failed unless the current <see cref="AssertionContext.AssertionFailureBehavior" /> indicates otherwise.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="actualXml"/>, <paramref name="searchedPath"/>, or <paramref name="options"/> is null.</exception> /// <remarks> /// <para> /// If <paramref name="expectedValue"/> is set to <c>null</c>, the assertion behaves like <see cref="Assert.Xml.Exists(string, IXmlPathLoose, XmlOptions)"/>. /// </para> /// </remarks> public static void Exists(string actualXml, IXmlPathLoose searchedPath, XmlOptions options, string expectedValue) { Exists(actualXml, searchedPath, options, expectedValue, null, null); }
/// <inheritdoc/> public abstract IXmlPathLoose Copy(IXmlPathLoose child);
/// <summary> /// Asserts that the XML fragment contains the searched element or attribute, and that this element or attribute is unique in the entire fragment. /// </summary> /// <remarks> /// <para> /// Options not related to the name case of elements and attributes are going to be ignored. /// </para> /// </remarks> /// <param name="actualXml">The actual XML fragment.</param> /// <param name="searchedPath">The path of the searched element or attribute in the XML fragment.</param> /// <param name="options">Options for the search.</param> /// <param name="messageFormat">The custom assertion message format, or null if none.</param> /// <param name="messageArgs">The custom assertion message arguments, or null if none.</param> /// <exception cref="AssertionException">Thrown if the verification failed unless the current <see cref="AssertionContext.AssertionFailureBehavior" /> indicates otherwise.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="actualXml"/>, <paramref name="searchedPath"/>, or <paramref name="options"/> is null.</exception> public static void IsUnique(string actualXml, IXmlPathLoose searchedPath, XmlOptions options, string messageFormat, params object[] messageArgs) { IsUnique(actualXml, searchedPath, options, null, messageFormat, messageFormat); }
/// <inheritdoc/> public override IXmlPathLoose Copy(IXmlPathLoose parent) { return new XmlPathLooseClosedAttribute((IXmlPathLooseClosed)parent, name); }
/// <summary> /// Asserts that the XML fragment contains the searched element or attribute, that it has the expected value, and that this element or attribute is unique in the entire fragment. /// </summary> /// <remarks> /// <para> /// If <paramref name="expectedValue"/> is set to <c>null</c>, the assertion behaves like <see cref="Assert.Xml.Exists(TextReader, IXmlPathLoose, XmlOptions, string, object[])"/>. /// </para> /// </remarks> /// <param name="actualXmlReader">A reader to get the actual XML fragment.</param> /// <param name="searchedPath">The path of the searched element or attribute in the XML fragment.</param> /// <param name="options">Options for the search.</param> /// <param name="expectedValue">The expected value of the searched item (element or attribute).</param> /// <param name="messageFormat">The custom assertion message format, or null if none.</param> /// <param name="messageArgs">The custom assertion message arguments, or null if none.</param> /// <exception cref="AssertionException">Thrown if the verification failed unless the current <see cref="AssertionContext.AssertionFailureBehavior" /> indicates otherwise.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="actualXmlReader"/>, <paramref name="searchedPath"/>, or <paramref name="options"/> is null.</exception> public static void IsUnique(TextReader actualXmlReader, IXmlPathLoose searchedPath, XmlOptions options, string expectedValue, string messageFormat, params object[] messageArgs) { if (actualXmlReader == null) throw new ArgumentNullException("actualXmlReader"); IsUnique(actualXmlReader.ReadToEnd(), searchedPath, options, expectedValue, messageFormat, messageArgs); }
/// <summary> /// Asserts that the XML fragment contains the searched element or attribute, that it has the expected value, and that this element or attribute is unique in the entire fragment. /// </summary> /// <remarks> /// <para> /// If <paramref name="expectedValue"/> is set to <c>null</c>, the assertion behaves like <see cref="Assert.Xml.Exists(string, IXmlPathLoose, XmlOptions, string, object[])"/>. /// </para> /// </remarks> /// <param name="actualXml">The actual XML fragment.</param> /// <param name="searchedPath">The path of the searched element or attribute in the XML fragment.</param> /// <param name="options">Options for the search.</param> /// <param name="expectedValue">The expected value of the searched item (element or attribute).</param> /// <param name="messageFormat">The custom assertion message format, or null if none.</param> /// <param name="messageArgs">The custom assertion message arguments, or null if none.</param> /// <exception cref="AssertionException">Thrown if the verification failed unless the current <see cref="AssertionContext.AssertionFailureBehavior" /> indicates otherwise.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="actualXml"/>, <paramref name="searchedPath"/>, or <paramref name="options"/> is null.</exception> public static void IsUnique(string actualXml, IXmlPathLoose searchedPath, XmlOptions options, string expectedValue, string messageFormat, params object[] messageArgs) { if (actualXml == null) throw new ArgumentNullException("actualXml"); if (searchedPath == null) throw new ArgumentNullException("searchedPath"); if (options == null) throw new ArgumentNullException("options"); AssertionHelper.Verify(() => { NodeFragment actual; try { actual = Parser.Run(actualXml, options.Value); } catch (XmlException exception) { return new AssertionFailureBuilder("Cannot parse the actual XML fragment.") .SetMessage(messageFormat, messageArgs) .AddException(exception) .ToAssertionFailure(); } int count = actual.CountAt(searchedPath, expectedValue, options.Value); if (count == 1) return null; var builder = new AssertionFailureBuilder("Expected the XML fragment to contain only once the searched XML element or attribute, " + (count == 0 ? "but none was found." : "But several were found.")) .SetMessage(messageFormat, messageArgs) .AddLabeledValue("Item searched", searchedPath.ToString()) .AddRawLabeledValue("Number of items found", count); if (expectedValue != null) { builder.AddLabeledValue("Expected value", expectedValue); } return builder.ToAssertionFailure(); }); }
/// <inheritdoc/> public override IXmlPathLoose Copy(IXmlPathLoose parent) { return(new XmlPathLooseOpenElement((IXmlPathLooseOpen)parent, name)); }