1- using System ;
2- using AngleSharp . Diffing . Core ;
1+ using System ;
2+ using Egil . AngleSharp . Diffing . Strategies ;
33using Shouldly ;
44using Xunit ;
55
6- namespace AngleSharp . Diffing
6+ namespace Egil . AngleSharp . Diffing
77{
8+
89 public class DiffBuilderTest
910 {
11+ private DiffingStrategyPipeline DefaultStrategy { get ; } = new DiffingStrategyPipelineBuilder ( ) . WithDefaultOptions ( ) . Build ( ) ;
12+
1013 [ Fact ( DisplayName = "Control and test html are set correctly" ) ]
1114 public void Test001 ( )
1215 {
1316 var control = "<p>control</p>" ;
1417 var test = "<p>test</p>" ;
1518
16- var sut = DiffBuilder
19+ var sut = new DiffBuilder ( DefaultStrategy )
1720 . Compare ( control )
1821 . WithTest ( test ) ;
1922
@@ -24,90 +27,42 @@ public void Test001()
2427 [ Fact ( DisplayName = "Builder throws if null is passed to control and test" ) ]
2528 public void Test002 ( )
2629 {
27- Should . Throw < ArgumentNullException > ( ( ) => DiffBuilder . Compare ( null ! ) ) . ParamName . ShouldBe ( nameof ( DiffBuilder . Control ) ) ;
28- Should . Throw < ArgumentNullException > ( ( ) => DiffBuilder . Compare ( "" ) . WithTest ( null ! ) ) . ParamName . ShouldBe ( nameof ( DiffBuilder . Test ) ) ;
30+ Should . Throw < ArgumentNullException > ( ( ) => new DiffBuilder ( DefaultStrategy ) . Compare ( null ! ) ) . ParamName . ShouldBe ( nameof ( DiffBuilder . Control ) ) ;
31+ Should . Throw < ArgumentNullException > ( ( ) => new DiffBuilder ( DefaultStrategy ) . Compare ( "" ) . WithTest ( null ! ) ) . ParamName . ShouldBe ( nameof ( DiffBuilder . Test ) ) ;
2932 }
3033
31-
32- [ Fact ( DisplayName = "Calling .Build() without adding strategies throws" ) ]
34+ [ Fact ( DisplayName = "Creating DiffBuilder with null strategies throws" ) ]
3335 public void Test3 ( )
3436 {
35- var control = "<p>control</p>" ;
36- var test = "<p>test</p>" ;
37-
38- Should . Throw < InvalidOperationException > ( ( ) => DiffBuilder . Compare ( control ) . WithTest ( test ) . Build ( ) ) ;
37+ Should . Throw < ArgumentNullException > ( ( ) => new DiffBuilder ( null ! ) ) ;
3938 }
4039
41- [ Fact ( DisplayName = "Calling .Build() without adding strategies throws" ) ]
42- public void Test4 ( )
43- {
44- var control = "<p>control</p>" ;
45- var test = "<p>test</p>" ;
46-
47- Should . Throw < InvalidOperationException > (
48- ( ) => DiffBuilder . Compare ( control )
49- . WithTest ( test )
50- . Build ( ) ) ;
51- }
52-
53- [ Fact ( DisplayName = "Calling .Build() without adding strategies throws" ) ]
54- public void Test5 ( )
55- {
56- var control = "<p>control</p>" ;
57- var test = "<p>test</p>" ;
58-
59- Should . Throw < InvalidOperationException > (
60- ( ) => DiffBuilder . Compare ( control )
61- . WithTest ( test )
62- . WithOneToOneNodeMatcher ( )
63- . WithAttributeNameMatcher ( )
64- . Build ( ) ) ;
65- }
66-
67-
6840 [ Fact ( DisplayName = "Calling Build() with DefaultOptions() returns expected diffs" ) ]
6941 public void Test6 ( )
7042 {
7143 var control = "<p>hello <em>world</em></p>" ;
7244 var test = "<p>world says <strong>hello</strong></p>" ;
7345
74- var diffs = DiffBuilder . Compare ( control )
46+ var diffs = new DiffBuilder ( DefaultStrategy )
47+ . Compare ( control )
7548 . WithTest ( test )
76- . WithDefaultOptions ( )
7749 . Build ( ) ;
7850
7951 diffs . ShouldNotBeEmpty ( ) ;
8052 }
8153
82- [ Fact ( DisplayName = "Adding custom strategies works " ) ]
83- public void Test7 ( )
54+ [ Fact ( DisplayName = "Test " ) ]
55+ public void MyTestMethod ( )
8456 {
85- var nodeFilterCalled = false ;
86- var attrFilterCalled = false ;
87- var nodeMatcherCalled = false ;
88- var attrMatcherCalled = false ;
89- var nodeComparerCalled = false ;
90- var attrComparerCalled = false ;
91- var control = @"<p foo=""bar"">hello <em>world</em></p>" ;
92- var test = @"<p foo=""bar"">world says <strong>hello</strong></p>" ;
57+ var control = "\r \n <h1>Hello world</h1>\r \n <h1>Hello world</h1>\r \n " ;
58+ var test = "\r \n <h1>Hello world</h1>\r \n <h1>Hello world</h1>\r \n " ;
9359
94- DiffBuilder . Compare ( control )
60+ var diffs = new DiffBuilder ( DefaultStrategy )
61+ . Compare ( control )
9562 . WithTest ( test )
96- . WithDefaultOptions ( )
97- . WithFilter ( ( in ComparisonSource source , FilterDecision currentDecision ) => { nodeFilterCalled = true ; return currentDecision ; } )
98- . WithFilter ( ( in AttributeComparisonSource source, FilterDecision currentDecision ) => { attrFilterCalled = true ; return currentDecision ; } )
99- . WithMatcher ( ( ctx , ctrlSrc , testSrc ) => { nodeMatcherCalled = true ; return Array . Empty < Comparison > ( ) ; } )
100- . WithMatcher ( ( ctx , ctrlSrc , testSrc ) => { attrMatcherCalled = true ; return Array . Empty < AttributeComparison > ( ) ; } )
101- . WithComparer ( ( in Comparison comparison , CompareResult currentDecision ) => { nodeComparerCalled = true ; return currentDecision ; } )
102- . WithComparer ( ( in AttributeComparison comparison , CompareResult currentDecision ) => { attrComparerCalled = true ; return currentDecision ; } )
10363 . Build ( ) ;
10464
105- nodeFilterCalled . ShouldBeTrue ( ) ;
106- attrFilterCalled . ShouldBeTrue ( ) ;
107- nodeMatcherCalled . ShouldBeTrue ( ) ;
108- attrMatcherCalled . ShouldBeTrue ( ) ;
109- nodeComparerCalled . ShouldBeTrue ( ) ;
110- attrComparerCalled . ShouldBeTrue ( ) ;
65+ diffs . ShouldBeEmpty ( ) ;
11166 }
11267 }
11368}
0 commit comments