Skip to content

Commit 4a4f692

Browse files
Merge pull request #10 from webexpress-framework/develop
0.0.10-alpha
2 parents 12fc57a + aa4e888 commit 4a4f692

272 files changed

Lines changed: 8812 additions & 3139 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test.yml renamed to .github/workflows/unittest-verification.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: UnitTests
1+
name: UnitTest-Verification
22

33
on:
44
workflow_dispatch:
@@ -10,14 +10,17 @@ on:
1010
jobs:
1111
build-and-test:
1212
runs-on: ubuntu-latest
13+
defaults:
14+
run:
15+
working-directory: src
1316
steps:
1417
- name: Checkout code
1518
uses: actions/checkout@v3
1619

1720
- name: Setup .NET
1821
uses: actions/setup-dotnet@v3
1922
with:
20-
dotnet-version: 9.x
23+
dotnet-version: 10.x
2124

2225
- name: Restore dependencies
2326
run: dotnet restore

icon.png

6.99 KB
Loading

src/WebExpress.WebCore.Test/Fixture/AssertExtensions.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ public static partial class AssertExtensions
2323
/// <param name="actual">The actual string to compare.</param>
2424
public static void EqualWithPlaceholders(string expected, string actual)
2525
{
26+
if (expected is null && actual is null)
27+
{
28+
return;
29+
}
30+
31+
Assert.NotNull(expected);
32+
Assert.NotNull(actual);
33+
2634
var str = RemoveLineBreaks(actual?.ToString());
2735
Assert.True(AreEqualWithPlaceholders(expected, str), $"Expected: {expected}{Environment.NewLine}Actual: {str}");
2836
}
@@ -47,15 +55,15 @@ public static void EqualWithPlaceholders(string expected, IHtmlNode actual)
4755
/// <returns>True if the actual string matches the expected string with placeholders; otherwise, false.</returns>
4856
private static bool AreEqualWithPlaceholders(string expected, string actual)
4957
{
50-
if (expected == null && actual == null)
58+
if (expected is null && actual is null)
5159
{
5260
return true;
5361
}
54-
else if (expected != null && actual == null)
62+
else if (expected is not null && actual is null)
5563
{
5664
return false;
5765
}
58-
else if (expected == null && actual != null)
66+
else if (expected is null && actual is not null)
5967
{
6068
return false;
6169
}

src/WebExpress.WebCore.Test/Fixture/UnitTestFixture.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public static ComponentHub CreateAndRegisterComponentHubMock()
9898
/// <param name="content">The content of the request.</param>
9999
/// <param name="uri">The URI of the request.</param>
100100
/// <returns>A fake request for testing.</returns>
101-
public static Request CrerateRequestMock(string content = "", string uri = "")
101+
public static IRequest CreateRequestMock(string content = "", string uri = "")
102102
{
103103
var context = CreateHttpContextMock(content);
104104

@@ -112,6 +112,25 @@ public static Request CrerateRequestMock(string content = "", string uri = "")
112112
return request;
113113
}
114114

115+
/// <summary>
116+
/// Create a fake request.
117+
/// </summary>
118+
/// <param name="uri">The URI of the request.</param>
119+
/// <returns>A fake request for testing.</returns>
120+
public static IRequest CreateRequestMock(IUri uri)
121+
{
122+
var context = CreateHttpContextMock();
123+
124+
var request = context.Request;
125+
126+
if (uri is not null)
127+
{
128+
request.Uri = uri as UriEndpoint;
129+
}
130+
131+
return request;
132+
}
133+
115134
/// <summary>
116135
/// Create a fake http context.
117136
/// </summary>
@@ -191,7 +210,7 @@ public static WebMessage.HttpContext CreateHttpContextMock(string content = "")
191210
/// <returns>A mock render context for testing.</returns>
192211
public static RenderContext CrerateRenderContextMock(IApplicationContext applicationContext = null, IEnumerable<Type> scopes = null)
193212
{
194-
var request = CrerateRequestMock();
213+
var request = CreateRequestMock();
195214

196215
return new RenderContext(null, CreratePageContextMock(applicationContext, scopes), request);
197216
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using WebExpress.WebCore.WebHtml;
2+
3+
namespace WebExpress.WebCore.Test.Html
4+
{
5+
/// <summary>
6+
/// Unit tests for the DeterministicId class.
7+
/// </summary>
8+
[Collection("NonParallelTests")]
9+
public class UnitTestDeterministicId
10+
{
11+
/// <summary>
12+
/// Tests the create method.
13+
/// </summary>
14+
[Fact]
15+
public void CreateSameCallsite()
16+
{
17+
// act
18+
var id1 = CallCreate();
19+
var id2 = CallCreate();
20+
21+
// validation
22+
Assert.NotEqual(id1, id2);
23+
}
24+
25+
/// <summary>
26+
/// Tests the create method.
27+
/// </summary>
28+
[Fact]
29+
public void CreateIndexes()
30+
{
31+
// act
32+
var id1 = CallCreate(0);
33+
var id2 = CallCreate(1);
34+
35+
// validation
36+
Assert.NotEqual(id1, id2);
37+
}
38+
39+
/// <summary>
40+
/// Tests the create method.
41+
/// </summary>
42+
[Fact]
43+
public void CreateDifferentCallsites()
44+
{
45+
// arrange
46+
var CallsiteA = new Func<string>(() => CallCreate());
47+
var CallsiteB = new Func<string>(() => CallCreate());
48+
49+
// act
50+
var id1 = CallsiteA();
51+
var id2 = CallsiteB();
52+
53+
// validation
54+
Assert.NotEqual(id1, id2);
55+
}
56+
57+
58+
/// <summary>
59+
/// Generates a deterministic identifier.
60+
/// <returns>
61+
/// A string that represents the generated deterministic identifier.
62+
/// </returns>
63+
private string CallCreate()
64+
{
65+
return DeterministicId.Create();
66+
}
67+
68+
/// <summary>
69+
/// Generates a deterministic identifier based on the specified index.
70+
/// </summary>
71+
/// <param name="contet">
72+
/// The optional content used to influence the generated identifier. If
73+
/// null, a default identifier is created.
74+
/// </param>
75+
/// <returns>
76+
/// A string that represents the generated deterministic identifier.
77+
/// </returns>
78+
private string CallCreate(object contet = null)
79+
{
80+
return DeterministicId.Create(contet);
81+
}
82+
}
83+
}

src/WebExpress.WebCore.Test/Html/UnitTestHtmlElement.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ public class UnitTestHtmlElement
1414
[Fact]
1515
public void FindSingel()
1616
{
17-
// preconditions
17+
// arrange
1818
var html = new HtmlElementTextContentDiv
1919
(
2020
new HtmlElementTextSemanticsI(),
2121
new HtmlElementTextSemanticsU(new HtmlElementTextSemanticsSpan()),
2222
new HtmlElementTextSemanticsB()
2323
);
2424

25-
// test execution
25+
// act
2626
var res = html.Find(x => x is HtmlElementTextSemanticsSpan).FirstOrDefault();
2727

2828
// validation
@@ -35,7 +35,7 @@ public void FindSingel()
3535
[Fact]
3636
public void Find()
3737
{
38-
// preconditions
38+
// arrange
3939
var html = new HtmlElement[]
4040
{
4141
new HtmlElementTextContentDiv
@@ -47,7 +47,7 @@ public void Find()
4747
new HtmlElementMultimediaImg()
4848
};
4949

50-
// test execution
50+
// act
5151
var res = html.Find(x => x is HtmlElementTextSemanticsSpan).FirstOrDefault();
5252

5353
// validation
@@ -60,10 +60,10 @@ public void Find()
6060
[Fact]
6161
public void AddClassTest()
6262
{
63-
// preconditions
63+
// arrange
6464
var div = new HtmlElementTextContentDiv();
6565

66-
// test execution
66+
// act
6767
div.AddClass("test-class");
6868

6969
// validation
@@ -76,11 +76,11 @@ public void AddClassTest()
7676
[Fact]
7777
public void RemoveClassTest()
7878
{
79-
// preconditions
79+
// arrange
8080
var div = new HtmlElementTextContentDiv();
8181
div.AddClass("test-class");
8282

83-
// test execution
83+
// act
8484
div.RemoveClass("test-class");
8585

8686
// validation
@@ -93,10 +93,10 @@ public void RemoveClassTest()
9393
[Fact]
9494
public void AddStyleTest()
9595
{
96-
// preconditions
96+
// arrange
9797
var div = new HtmlElementTextContentDiv();
9898

99-
// test execution
99+
// act
100100
div.AddStyle("color:red;");
101101

102102
// validation
@@ -109,11 +109,11 @@ public void AddStyleTest()
109109
[Fact]
110110
public void RemoveStyleTest()
111111
{
112-
// preconditions
112+
// arrange
113113
var div = new HtmlElementTextContentDiv();
114114
div.AddStyle("color", "red");
115115

116-
// test execution
116+
// act
117117
div.RemoveStyle("color");
118118

119119
// validation
@@ -126,10 +126,10 @@ public void RemoveStyleTest()
126126
[Fact]
127127
public void AddMultipleClassesTest()
128128
{
129-
// preconditions
129+
// arrange
130130
var div = new HtmlElementTextContentDiv();
131131

132-
// test execution
132+
// act
133133
div.AddClass("class1");
134134
div.AddClass("class2");
135135

@@ -143,12 +143,12 @@ public void AddMultipleClassesTest()
143143
[Fact]
144144
public void RemoveOneOfMultipleClassesTest()
145145
{
146-
// preconditions
146+
// arrange
147147
var div = new HtmlElementTextContentDiv();
148148
div.AddClass("class1");
149149
div.AddClass("class2");
150150

151-
// test execution
151+
// act
152152
div.RemoveClass("class1");
153153

154154
// validation
@@ -162,10 +162,10 @@ public void RemoveOneOfMultipleClassesTest()
162162
[Fact]
163163
public void AddMultipleStylesTest()
164164
{
165-
// preconditions
165+
// arrange
166166
var div = new HtmlElementTextContentDiv();
167167

168-
// test execution
168+
// act
169169
div.AddStyle("color:red;");
170170
div.AddStyle("background:blue;");
171171

@@ -180,12 +180,12 @@ public void AddMultipleStylesTest()
180180
[Fact]
181181
public void RemoveOneOfMultipleStylesTest()
182182
{
183-
// preconditions
183+
// arrange
184184
var div = new HtmlElementTextContentDiv();
185185
div.AddStyle("color:red;");
186186
div.AddStyle("background:blue;");
187187

188-
// test execution
188+
// act
189189
div.RemoveStyle("color:red;");
190190

191191
// validation
@@ -199,7 +199,7 @@ public void RemoveOneOfMultipleStylesTest()
199199
[Fact]
200200
public void ToStringEmptyDivTest()
201201
{
202-
// preconditions
202+
// arrange
203203
var div = new HtmlElementTextContentDiv();
204204

205205
// validation
@@ -212,7 +212,7 @@ public void ToStringEmptyDivTest()
212212
[Fact]
213213
public void ToStringWithChildrenTest()
214214
{
215-
// preconditions
215+
// arrange
216216
var div = new HtmlElementTextContentDiv(
217217
new HtmlElementTextSemanticsB(),
218218
new HtmlElementTextSemanticsI()

0 commit comments

Comments
 (0)