|
1 | | -using System; |
| 1 | +namespace AngleSharp.Diffing.Core; |
2 | 2 |
|
3 | | -using Shouldly; |
4 | | - |
5 | | -using Xunit; |
6 | | - |
7 | | -namespace AngleSharp.Diffing.Core |
| 3 | +public class AttributeComparisonSourceTest : DiffingTestBase |
8 | 4 | { |
9 | | - public class AttributeComparisonSourceTest : DiffingTestBase |
| 5 | + public AttributeComparisonSourceTest(DiffingTestFixture fixture) : base(fixture) |
10 | 6 | { |
11 | | - public AttributeComparisonSourceTest(DiffingTestFixture fixture) : base(fixture) |
12 | | - { |
13 | | - } |
14 | | - |
15 | | - [Fact(DisplayName = "When a null is used for element source, an exception is thrown")] |
16 | | - public void Test003() |
17 | | - { |
18 | | - Should.Throw<ArgumentNullException>(() => new AttributeComparisonSource(null!, new ComparisonSource())); |
19 | | - Should.Throw<ArgumentNullException>(() => new AttributeComparisonSource("", new ComparisonSource())); |
20 | | - } |
21 | | - |
22 | | - [Fact(DisplayName = "When a element source does not contain the specified attribute name, an exception is thrown")] |
23 | | - public void Test004() |
24 | | - { |
25 | | - var elementSource = ToComparisonSource(@"<br>", ComparisonSourceType.Control); |
| 7 | + } |
26 | 8 |
|
27 | | - Should.Throw<ArgumentException>(() => new AttributeComparisonSource("notFoundAttr", elementSource)); |
28 | | - } |
| 9 | + [Fact(DisplayName = "When a null is used for element source, an exception is thrown")] |
| 10 | + public void Test003() |
| 11 | + { |
| 12 | + Should.Throw<ArgumentNullException>(() => new AttributeComparisonSource(null!, new ComparisonSource())); |
| 13 | + Should.Throw<ArgumentNullException>(() => new AttributeComparisonSource("", new ComparisonSource())); |
| 14 | + } |
29 | 15 |
|
30 | | - [Fact(DisplayName = "Two sources are equal if all their properties are equal")] |
31 | | - public void Test1() |
32 | | - { |
33 | | - var elementSource = ToComparisonSource(@"<br foo=""bar"">", ComparisonSourceType.Control); |
34 | | - var source = new AttributeComparisonSource("foo", elementSource); |
35 | | - var otherSource = new AttributeComparisonSource("foo", elementSource); |
| 16 | + [Fact(DisplayName = "When a element source does not contain the specified attribute name, an exception is thrown")] |
| 17 | + public void Test004() |
| 18 | + { |
| 19 | + var elementSource = ToComparisonSource(@"<br>", ComparisonSourceType.Control); |
36 | 20 |
|
37 | | - source.Equals(otherSource).ShouldBeTrue(); |
38 | | - source.Equals((object)otherSource).ShouldBeTrue(); |
39 | | - (source == otherSource).ShouldBeTrue(); |
40 | | - (source != otherSource).ShouldBeFalse(); |
41 | | - } |
| 21 | + Should.Throw<ArgumentException>(() => new AttributeComparisonSource("notFoundAttr", elementSource)); |
| 22 | + } |
42 | 23 |
|
43 | | - [Fact(DisplayName = "Two sources are not equal if their attribute is different")] |
44 | | - public void Test11() |
45 | | - { |
46 | | - var elementSource = ToComparisonSource(@"<br foo=""bar"" bar=""baz"">", ComparisonSourceType.Control); |
47 | | - var source = new AttributeComparisonSource("foo", elementSource); |
48 | | - var otherSource = new AttributeComparisonSource("bar", elementSource); |
| 24 | + [Fact(DisplayName = "Two sources are equal if all their properties are equal")] |
| 25 | + public void Test1() |
| 26 | + { |
| 27 | + var elementSource = ToComparisonSource(@"<br foo=""bar"">", ComparisonSourceType.Control); |
| 28 | + var source = new AttributeComparisonSource("foo", elementSource); |
| 29 | + var otherSource = new AttributeComparisonSource("foo", elementSource); |
| 30 | + |
| 31 | + source.Equals(otherSource).ShouldBeTrue(); |
| 32 | + source.Equals((object)otherSource).ShouldBeTrue(); |
| 33 | + (source == otherSource).ShouldBeTrue(); |
| 34 | + (source != otherSource).ShouldBeFalse(); |
| 35 | + } |
49 | 36 |
|
50 | | - source.Equals(otherSource).ShouldBeFalse(); |
51 | | - (source == otherSource).ShouldBeFalse(); |
52 | | - (source != otherSource).ShouldBeTrue(); |
53 | | - } |
| 37 | + [Fact(DisplayName = "Two sources are not equal if their attribute is different")] |
| 38 | + public void Test11() |
| 39 | + { |
| 40 | + var elementSource = ToComparisonSource(@"<br foo=""bar"" bar=""baz"">", ComparisonSourceType.Control); |
| 41 | + var source = new AttributeComparisonSource("foo", elementSource); |
| 42 | + var otherSource = new AttributeComparisonSource("bar", elementSource); |
54 | 43 |
|
55 | | - [Fact(DisplayName = "Two sources are not equal if their element source is different")] |
56 | | - public void Test3() |
57 | | - { |
58 | | - var elementSource = ToComparisonSource(@"<br foo=""bar"" bar=""baz"">", ComparisonSourceType.Control); |
59 | | - var otherElementSource = ToComparisonSource(@"<br foo=""bar"" bar=""baz"">", ComparisonSourceType.Control); |
60 | | - var source = new AttributeComparisonSource("foo", elementSource); |
61 | | - var otherSource = new AttributeComparisonSource("bar", otherElementSource); |
| 44 | + source.Equals(otherSource).ShouldBeFalse(); |
| 45 | + (source == otherSource).ShouldBeFalse(); |
| 46 | + (source != otherSource).ShouldBeTrue(); |
| 47 | + } |
62 | 48 |
|
63 | | - source.Equals(otherSource).ShouldBeFalse(); |
64 | | - (source == otherSource).ShouldBeFalse(); |
65 | | - (source != otherSource).ShouldBeTrue(); |
66 | | - } |
| 49 | + [Fact(DisplayName = "Two sources are not equal if their element source is different")] |
| 50 | + public void Test3() |
| 51 | + { |
| 52 | + var elementSource = ToComparisonSource(@"<br foo=""bar"" bar=""baz"">", ComparisonSourceType.Control); |
| 53 | + var otherElementSource = ToComparisonSource(@"<br foo=""bar"" bar=""baz"">", ComparisonSourceType.Control); |
| 54 | + var source = new AttributeComparisonSource("foo", elementSource); |
| 55 | + var otherSource = new AttributeComparisonSource("bar", otherElementSource); |
| 56 | + |
| 57 | + source.Equals(otherSource).ShouldBeFalse(); |
| 58 | + (source == otherSource).ShouldBeFalse(); |
| 59 | + (source != otherSource).ShouldBeTrue(); |
| 60 | + } |
67 | 61 |
|
68 | | - [Fact(DisplayName = "GetHashCode correctly returns same value for two equal sources")] |
69 | | - public void Test001() |
70 | | - { |
71 | | - var elementSource = ToComparisonSource(@"<br foo=""bar"">", ComparisonSourceType.Control); |
72 | | - var source = new AttributeComparisonSource("foo", elementSource); |
73 | | - var otherSource = new AttributeComparisonSource("foo", elementSource); |
| 62 | + [Fact(DisplayName = "GetHashCode correctly returns same value for two equal sources")] |
| 63 | + public void Test001() |
| 64 | + { |
| 65 | + var elementSource = ToComparisonSource(@"<br foo=""bar"">", ComparisonSourceType.Control); |
| 66 | + var source = new AttributeComparisonSource("foo", elementSource); |
| 67 | + var otherSource = new AttributeComparisonSource("foo", elementSource); |
74 | 68 |
|
75 | | - source.GetHashCode().ShouldBe(otherSource.GetHashCode()); |
76 | | - } |
| 69 | + source.GetHashCode().ShouldBe(otherSource.GetHashCode()); |
| 70 | + } |
77 | 71 |
|
78 | | - [Fact(DisplayName = "GetHashCode correctly returns different values for two unequal sources")] |
79 | | - public void Test002() |
80 | | - { |
81 | | - var elementSource = ToComparisonSource(@"<br foo=""bar"" bar=""baz"">", ComparisonSourceType.Control); |
82 | | - var otherElementSource = ToComparisonSource(@"<br foo=""bar"" bar=""baz"">", ComparisonSourceType.Control); |
83 | | - var source = new AttributeComparisonSource("foo", elementSource); |
84 | | - var otherSource = new AttributeComparisonSource("bar", otherElementSource); |
| 72 | + [Fact(DisplayName = "GetHashCode correctly returns different values for two unequal sources")] |
| 73 | + public void Test002() |
| 74 | + { |
| 75 | + var elementSource = ToComparisonSource(@"<br foo=""bar"" bar=""baz"">", ComparisonSourceType.Control); |
| 76 | + var otherElementSource = ToComparisonSource(@"<br foo=""bar"" bar=""baz"">", ComparisonSourceType.Control); |
| 77 | + var source = new AttributeComparisonSource("foo", elementSource); |
| 78 | + var otherSource = new AttributeComparisonSource("bar", otherElementSource); |
85 | 79 |
|
86 | | - source.GetHashCode().ShouldNotBe(otherSource.GetHashCode()); |
87 | | - } |
| 80 | + source.GetHashCode().ShouldNotBe(otherSource.GetHashCode()); |
88 | 81 | } |
89 | 82 | } |
0 commit comments