Esempio n. 1
0
        /// <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());
        }
Esempio n. 2
0
        /// <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();
        }
Esempio n. 3
0
        /// <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());
        }