Skip to content

Commit f3bc39d

Browse files
Add unit test for HtmlElementErrorEventArgs.cs file (#13512)
Add unit test for HtmlElementErrorEventArgs file
1 parent 11bc0c1 commit f3bc39d

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace System.Windows.Forms.Tests;
5+
6+
public class HtmlElementErrorEventArgsTests
7+
{
8+
[Fact]
9+
public void HtmlElementErrorEventArgs_InitializesProperties()
10+
{
11+
string description = "Script error";
12+
string urlString = "https://example.com/page";
13+
int lineNumber = 42;
14+
15+
HtmlElementErrorEventArgs args = new(description, urlString, lineNumber);
16+
17+
args.Description.Should().Be(description);
18+
args.LineNumber.Should().Be(lineNumber);
19+
args.Url.Should().Be(new Uri(urlString));
20+
args.Handled.Should().BeFalse();
21+
args.Handled = true;
22+
args.Handled.Should().BeTrue();
23+
}
24+
25+
[Fact]
26+
public void HtmlElementErrorEventArgs_Url_CachesUriInstance()
27+
{
28+
HtmlElementErrorEventArgs args = new("desc", "https://test", 1);
29+
30+
Uri url1 = args.Url;
31+
Uri url2 = args.Url;
32+
33+
url1.Should().BeSameAs(url2);
34+
}
35+
36+
[Fact]
37+
public void HtmlElementErrorEventArgs_Url_ThrowsOnInvalidUri()
38+
{
39+
HtmlElementErrorEventArgs args = new("desc", "not a uri", 1);
40+
41+
Action action = () => _ = args.Url;
42+
43+
action.Should().Throw<UriFormatException>();
44+
}
45+
}

0 commit comments

Comments
 (0)