示例#1
0
        /// <summary>
        /// The CSS selector element matcher.
        /// </summary>
        public static IEnumerable <Comparison> Match(IDiffContext context,
                                                     SourceCollection controlSources,
                                                     SourceCollection testSources)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (controlSources is null)
            {
                throw new ArgumentNullException(nameof(controlSources));
            }
            if (testSources is null)
            {
                throw new ArgumentNullException(nameof(testSources));
            }

            foreach (var control in controlSources.GetUnmatched())
            {
                if (control.Node.TryGetAttrValue(DIFF_MATCH_ATTR_NAME, out string cssSelector))
                {
                    if (TryGetTestNode(context, cssSelector, out var testNode))
                    {
                        var test = new ComparisonSource(testNode, ComparisonSourceType.Test);
                        yield return(new Comparison(control, test));
                    }
                }
            }

            yield break;
        }
        public void Tes76(string html)
        {
            var sut    = new TextNodeFilter(WhitespaceOption.Normalize);
            var root   = ToNode(html);
            var source = new ComparisonSource(root.FirstChild.FirstChild.FirstChild, 0, "dummypath", ComparisonSourceType.Control);

            sut.Filter(source, FilterDecision.Keep).ShouldBe(FilterDecision.Keep);
        }
示例#3
0
        public void Test001(string controlHtml, string testHtml)
        {
            var sut           = new TextNodeComparer(WhitespaceOption.Preserve);
            var controlSource = new ComparisonSource(ToNode(controlHtml).FirstChild.FirstChild.FirstChild, 0, "dummypath", ComparisonSourceType.Control);
            var testSource    = new ComparisonSource(ToNode(testHtml).FirstChild.FirstChild.FirstChild, 0, "dummypath", ComparisonSourceType.Test);
            var comparison    = new Comparison(controlSource, testSource);

            sut.Compare(comparison, CompareResult.Different).ShouldBe(CompareResult.Same);
        }
示例#4
0
        private Comparison ToStyleComparison(string controlStyleText, string testStyleText)
        {
            var controlStyle  = ToComparisonSource($@"<style type=""text/css"">{controlStyleText}</style>");
            var controlSource = new ComparisonSource(controlStyle.Node.FirstChild, 0, controlStyle.Path, ComparisonSourceType.Control);
            var testStyle     = ToComparisonSource($@"<style type=""text/css"">{testStyleText}</style>");
            var testSource    = new ComparisonSource(testStyle.Node.FirstChild, 0, testStyle.Path, ComparisonSourceType.Test);

            return(new Comparison(controlSource, testSource));
        }
示例#5
0
        public void Test012(string controlHtml)
        {
            var sut             = new TextNodeComparer();
            var paragraphSource = ToComparisonSource(controlHtml);
            var controlSource   = new ComparisonSource(paragraphSource.Node.FirstChild, 0, paragraphSource.Path, ComparisonSourceType.Control);
            var testSource      = ToComparisonSource("1234", ComparisonSourceType.Test);
            var comparison      = new Comparison(controlSource, testSource);

            sut.Compare(comparison, CompareResult.Different).ShouldBe(CompareResult.Same);
        }
示例#6
0
        public void Test011()
        {
            var sut             = new TextNodeComparer(ignoreCase: true);
            var paragraphSource = ToComparisonSource(@"<p diff:regex>FOO\d{4}</p>");
            var controlSource   = new ComparisonSource(paragraphSource.Node.FirstChild, 0, paragraphSource.Path, ComparisonSourceType.Control);
            var testSource      = ToComparisonSource("foo1234", ComparisonSourceType.Test);
            var comparison      = new Comparison(controlSource, testSource);

            sut.Compare(comparison, CompareResult.Different).ShouldBe(CompareResult.Same);
        }
示例#7
0
        public void Test009(string controlHtml)
        {
            var sut           = new TextNodeComparer(ignoreCase: true);
            var rootSource    = ToComparisonSource(controlHtml);
            var controlSource = new ComparisonSource(rootSource.Node.FirstChild.FirstChild.FirstChild, 0, rootSource.Path, ComparisonSourceType.Control);
            var testSource    = ToComparisonSource("hello world", ComparisonSourceType.Test);
            var comparison    = new Comparison(controlSource, testSource);

            sut.Compare(comparison, CompareResult.Different).ShouldBe(CompareResult.Different);
        }
示例#8
0
        public void Test005(string tag)
        {
            var sut           = new TextNodeComparer(WhitespaceOption.Normalize);
            var elm           = ToComparisonSource($"<{tag}>foo   bar</{tag}>");
            var controlSource = new ComparisonSource(elm.Node.FirstChild, 0, elm.Path, ComparisonSourceType.Control);
            var testSource    = ToComparisonSource("foo bar", ComparisonSourceType.Test);
            var comparison    = new Comparison(controlSource, testSource);

            sut.Compare(comparison, CompareResult.Different).ShouldBe(CompareResult.Different);
        }
示例#9
0
        private TestExpressionInfo(EventCriteria eventCriteria, InputCriteria globalCriteria, Condition condition, object value)
        {
            Contract.Requires(value != null);

            Event = eventCriteria;
            Input = globalCriteria;
            Condition = condition;
            _value = value;
            Source = Get(globalCriteria, eventCriteria);
        }
示例#10
0
        private TestExpressionInfo(EventCriteria eventCriteria, InputCriteria globalCriteria, Condition condition, object value)
        {
            Contract.Requires(value != null);

            Event     = eventCriteria;
            Input     = globalCriteria;
            Condition = condition;
            _value    = value;
            Source    = Get(globalCriteria, eventCriteria);
        }
示例#11
0
 public static string NodeName(this ComparisonSource source) => source.Node.NodeType.ToString().ToLowerInvariant();