diff --git a/.github/workflows/test.yml b/.github/workflows/unittest-verification.yml
similarity index 82%
rename from .github/workflows/test.yml
rename to .github/workflows/unittest-verification.yml
index ff6d68d..a820d77 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/unittest-verification.yml
@@ -1,4 +1,4 @@
-name: UnitTests
+name: UnitTest-Verification
on:
workflow_dispatch:
@@ -10,6 +10,9 @@ on:
jobs:
build-and-test:
runs-on: ubuntu-latest
+ defaults:
+ run:
+ working-directory: src
steps:
- name: Checkout code
uses: actions/checkout@v3
@@ -17,7 +20,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
- dotnet-version: 9.x
+ dotnet-version: 10.x
- name: Restore dependencies
run: dotnet restore
diff --git a/icon.png b/icon.png
index 7ce9270..01bf63f 100644
Binary files a/icon.png and b/icon.png differ
diff --git a/src/WebExpress.WebCore.Test/Fixture/AssertExtensions.cs b/src/WebExpress.WebCore.Test/Fixture/AssertExtensions.cs
index f241278..e6fb0b4 100644
--- a/src/WebExpress.WebCore.Test/Fixture/AssertExtensions.cs
+++ b/src/WebExpress.WebCore.Test/Fixture/AssertExtensions.cs
@@ -23,6 +23,14 @@ public static partial class AssertExtensions
/// The actual string to compare.
public static void EqualWithPlaceholders(string expected, string actual)
{
+ if (expected is null && actual is null)
+ {
+ return;
+ }
+
+ Assert.NotNull(expected);
+ Assert.NotNull(actual);
+
var str = RemoveLineBreaks(actual?.ToString());
Assert.True(AreEqualWithPlaceholders(expected, str), $"Expected: {expected}{Environment.NewLine}Actual: {str}");
}
@@ -47,15 +55,15 @@ public static void EqualWithPlaceholders(string expected, IHtmlNode actual)
/// True if the actual string matches the expected string with placeholders; otherwise, false.
private static bool AreEqualWithPlaceholders(string expected, string actual)
{
- if (expected == null && actual == null)
+ if (expected is null && actual is null)
{
return true;
}
- else if (expected != null && actual == null)
+ else if (expected is not null && actual is null)
{
return false;
}
- else if (expected == null && actual != null)
+ else if (expected is null && actual is not null)
{
return false;
}
diff --git a/src/WebExpress.WebCore.Test/Fixture/UnitTestFixture.cs b/src/WebExpress.WebCore.Test/Fixture/UnitTestFixture.cs
index bf3684b..aa472fd 100644
--- a/src/WebExpress.WebCore.Test/Fixture/UnitTestFixture.cs
+++ b/src/WebExpress.WebCore.Test/Fixture/UnitTestFixture.cs
@@ -98,7 +98,7 @@ public static ComponentHub CreateAndRegisterComponentHubMock()
/// The content of the request.
/// The URI of the request.
/// A fake request for testing.
- public static Request CrerateRequestMock(string content = "", string uri = "")
+ public static IRequest CreateRequestMock(string content = "", string uri = "")
{
var context = CreateHttpContextMock(content);
@@ -112,6 +112,25 @@ public static Request CrerateRequestMock(string content = "", string uri = "")
return request;
}
+ ///
+ /// Create a fake request.
+ ///
+ /// The URI of the request.
+ /// A fake request for testing.
+ public static IRequest CreateRequestMock(IUri uri)
+ {
+ var context = CreateHttpContextMock();
+
+ var request = context.Request;
+
+ if (uri is not null)
+ {
+ request.Uri = uri as UriEndpoint;
+ }
+
+ return request;
+ }
+
///
/// Create a fake http context.
///
@@ -191,7 +210,7 @@ public static WebMessage.HttpContext CreateHttpContextMock(string content = "")
/// A mock render context for testing.
public static RenderContext CrerateRenderContextMock(IApplicationContext applicationContext = null, IEnumerable scopes = null)
{
- var request = CrerateRequestMock();
+ var request = CreateRequestMock();
return new RenderContext(null, CreratePageContextMock(applicationContext, scopes), request);
}
diff --git a/src/WebExpress.WebCore.Test/Html/UnitTestDeterministicId.cs b/src/WebExpress.WebCore.Test/Html/UnitTestDeterministicId.cs
new file mode 100644
index 0000000..d2aec90
--- /dev/null
+++ b/src/WebExpress.WebCore.Test/Html/UnitTestDeterministicId.cs
@@ -0,0 +1,83 @@
+using WebExpress.WebCore.WebHtml;
+
+namespace WebExpress.WebCore.Test.Html
+{
+ ///
+ /// Unit tests for the DeterministicId class.
+ ///
+ [Collection("NonParallelTests")]
+ public class UnitTestDeterministicId
+ {
+ ///
+ /// Tests the create method.
+ ///
+ [Fact]
+ public void CreateSameCallsite()
+ {
+ // act
+ var id1 = CallCreate();
+ var id2 = CallCreate();
+
+ // validation
+ Assert.NotEqual(id1, id2);
+ }
+
+ ///
+ /// Tests the create method.
+ ///
+ [Fact]
+ public void CreateIndexes()
+ {
+ // act
+ var id1 = CallCreate(0);
+ var id2 = CallCreate(1);
+
+ // validation
+ Assert.NotEqual(id1, id2);
+ }
+
+ ///
+ /// Tests the create method.
+ ///
+ [Fact]
+ public void CreateDifferentCallsites()
+ {
+ // arrange
+ var CallsiteA = new Func(() => CallCreate());
+ var CallsiteB = new Func(() => CallCreate());
+
+ // act
+ var id1 = CallsiteA();
+ var id2 = CallsiteB();
+
+ // validation
+ Assert.NotEqual(id1, id2);
+ }
+
+
+ ///
+ /// Generates a deterministic identifier.
+ ///
+ /// A string that represents the generated deterministic identifier.
+ ///
+ private string CallCreate()
+ {
+ return DeterministicId.Create();
+ }
+
+ ///
+ /// Generates a deterministic identifier based on the specified index.
+ ///
+ ///
+ /// The optional content used to influence the generated identifier. If
+ /// null, a default identifier is created.
+ ///
+ ///
+ /// A string that represents the generated deterministic identifier.
+ ///
+ private string CallCreate(object contet = null)
+ {
+ return DeterministicId.Create(contet);
+ }
+ }
+}
diff --git a/src/WebExpress.WebCore.Test/Html/UnitTestHtmlElement.cs b/src/WebExpress.WebCore.Test/Html/UnitTestHtmlElement.cs
index e4df43e..bfcc0ef 100644
--- a/src/WebExpress.WebCore.Test/Html/UnitTestHtmlElement.cs
+++ b/src/WebExpress.WebCore.Test/Html/UnitTestHtmlElement.cs
@@ -14,7 +14,7 @@ public class UnitTestHtmlElement
[Fact]
public void FindSingel()
{
- // preconditions
+ // arrange
var html = new HtmlElementTextContentDiv
(
new HtmlElementTextSemanticsI(),
@@ -22,7 +22,7 @@ public void FindSingel()
new HtmlElementTextSemanticsB()
);
- // test execution
+ // act
var res = html.Find(x => x is HtmlElementTextSemanticsSpan).FirstOrDefault();
// validation
@@ -35,7 +35,7 @@ public void FindSingel()
[Fact]
public void Find()
{
- // preconditions
+ // arrange
var html = new HtmlElement[]
{
new HtmlElementTextContentDiv
@@ -47,7 +47,7 @@ public void Find()
new HtmlElementMultimediaImg()
};
- // test execution
+ // act
var res = html.Find(x => x is HtmlElementTextSemanticsSpan).FirstOrDefault();
// validation
@@ -60,10 +60,10 @@ public void Find()
[Fact]
public void AddClassTest()
{
- // preconditions
+ // arrange
var div = new HtmlElementTextContentDiv();
- // test execution
+ // act
div.AddClass("test-class");
// validation
@@ -76,11 +76,11 @@ public void AddClassTest()
[Fact]
public void RemoveClassTest()
{
- // preconditions
+ // arrange
var div = new HtmlElementTextContentDiv();
div.AddClass("test-class");
- // test execution
+ // act
div.RemoveClass("test-class");
// validation
@@ -93,10 +93,10 @@ public void RemoveClassTest()
[Fact]
public void AddStyleTest()
{
- // preconditions
+ // arrange
var div = new HtmlElementTextContentDiv();
- // test execution
+ // act
div.AddStyle("color:red;");
// validation
@@ -109,11 +109,11 @@ public void AddStyleTest()
[Fact]
public void RemoveStyleTest()
{
- // preconditions
+ // arrange
var div = new HtmlElementTextContentDiv();
div.AddStyle("color", "red");
- // test execution
+ // act
div.RemoveStyle("color");
// validation
@@ -126,10 +126,10 @@ public void RemoveStyleTest()
[Fact]
public void AddMultipleClassesTest()
{
- // preconditions
+ // arrange
var div = new HtmlElementTextContentDiv();
- // test execution
+ // act
div.AddClass("class1");
div.AddClass("class2");
@@ -143,12 +143,12 @@ public void AddMultipleClassesTest()
[Fact]
public void RemoveOneOfMultipleClassesTest()
{
- // preconditions
+ // arrange
var div = new HtmlElementTextContentDiv();
div.AddClass("class1");
div.AddClass("class2");
- // test execution
+ // act
div.RemoveClass("class1");
// validation
@@ -162,10 +162,10 @@ public void RemoveOneOfMultipleClassesTest()
[Fact]
public void AddMultipleStylesTest()
{
- // preconditions
+ // arrange
var div = new HtmlElementTextContentDiv();
- // test execution
+ // act
div.AddStyle("color:red;");
div.AddStyle("background:blue;");
@@ -180,12 +180,12 @@ public void AddMultipleStylesTest()
[Fact]
public void RemoveOneOfMultipleStylesTest()
{
- // preconditions
+ // arrange
var div = new HtmlElementTextContentDiv();
div.AddStyle("color:red;");
div.AddStyle("background:blue;");
- // test execution
+ // act
div.RemoveStyle("color:red;");
// validation
@@ -199,7 +199,7 @@ public void RemoveOneOfMultipleStylesTest()
[Fact]
public void ToStringEmptyDivTest()
{
- // preconditions
+ // arrange
var div = new HtmlElementTextContentDiv();
// validation
@@ -212,7 +212,7 @@ public void ToStringEmptyDivTest()
[Fact]
public void ToStringWithChildrenTest()
{
- // preconditions
+ // arrange
var div = new HtmlElementTextContentDiv(
new HtmlElementTextSemanticsB(),
new HtmlElementTextSemanticsI()
diff --git a/src/WebExpress.WebCore.Test/Html/UnitTestHtmlElementExtension.cs b/src/WebExpress.WebCore.Test/Html/UnitTestHtmlElementExtension.cs
index 7bfe0a0..3375d00 100644
--- a/src/WebExpress.WebCore.Test/Html/UnitTestHtmlElementExtension.cs
+++ b/src/WebExpress.WebCore.Test/Html/UnitTestHtmlElementExtension.cs
@@ -22,10 +22,10 @@ public class UnitTestHtmlElementExtension
[InlineData(null, "new", "new")]
public void AddClass(string initial, string toAdd, string expected)
{
- // preconditions
+ // arrange
var element = new HtmlElementTextContentDiv { Class = initial } as IHtmlNode;
- // test execution
+ // act
element.AddClass(toAdd);
Assert.Equal(expected, (element as IHtmlElement).Class);
@@ -42,10 +42,10 @@ public void AddClass(string initial, string toAdd, string expected)
[InlineData(null, "gamma", "")]
public void RemoveClass(string initial, string toRemove, string expected)
{
- // preconditions
+ // arrange
var element = new HtmlElementTextContentDiv { Class = initial } as IHtmlNode;
- // test execution
+ // act
element.RemoveClass(toRemove);
// validation
@@ -68,10 +68,10 @@ public void RemoveClass(string initial, string toRemove, string expected)
[InlineData(null, "new", "new")]
public void AddStyle(string initial, string toAdd, string expected)
{
- // preconditions
+ // arrange
var element = new HtmlElementTextContentDiv { Style = initial } as IHtmlNode;
- // test execution
+ // act
element.AddStyle(toAdd);
// validation
@@ -91,10 +91,10 @@ public void AddStyle(string initial, string toAdd, string expected)
[InlineData(null, "gamma", "")]
public void RemoveStyle(string initial, string toRemove, string expected)
{
- // preconditions
+ // arrange
var element = new HtmlElementTextContentDiv { Style = initial } as IHtmlNode;
- // test execution
+ // act
element.RemoveStyle(toRemove);
// validation
@@ -109,10 +109,10 @@ public void RemoveStyle(string initial, string toRemove, string expected)
[InlineData("data-id", "42", "data-id=42")]
public void AddUserAttribute(string name, string value, string expected)
{
- // preconditions
+ // arrange
var element = new HtmlElementTextContentDiv() as IHtmlNode;
- // test execution
+ // act
if (!string.IsNullOrWhiteSpace(value))
{
element.AddUserAttribute(name, value);
@@ -145,11 +145,11 @@ public void AddUserAttribute(string name, string value, string expected)
[InlineData("data-id", "42")]
public void RemoveUserAttribute(string name, string value)
{
- // preconditions
+ // arrange
var element = new HtmlElementTextContentDiv() as IHtmlNode;
element.AddUserAttribute(name, value);
- // test execution
+ // act
element.RemoveUserAttribute(name);
// validation
@@ -162,7 +162,7 @@ public void RemoveUserAttribute(string name, string value)
[Fact]
public void Find()
{
- // preconditions
+ // arrange
var root = new HtmlElementTextContentDiv();
var node = root as IHtmlNode;
var child1 = new HtmlElementTextSemanticsSpan();
@@ -170,7 +170,7 @@ public void Find()
root.Add(child1);
root.Add(child2);
- // test execution
+ // act
var result = node.Find(e => e is HtmlElementTextSemanticsSpan).ToList();
// validation
diff --git a/src/WebExpress.WebCore.Test/Html/UnitTestHtmlElementFieldLabel.cs b/src/WebExpress.WebCore.Test/Html/UnitTestHtmlElementFieldLabel.cs
index cd716f1..de21028 100644
--- a/src/WebExpress.WebCore.Test/Html/UnitTestHtmlElementFieldLabel.cs
+++ b/src/WebExpress.WebCore.Test/Html/UnitTestHtmlElementFieldLabel.cs
@@ -14,7 +14,7 @@ public class UnitTestHtmlElementFieldLabel
[Fact]
public void Empty()
{
- // test execution
+ // act
var html = new HtmlElementFieldLabel();
Assert.Equal(@"", html.Trim());
@@ -26,7 +26,7 @@ public void Empty()
[Fact]
public void TextAtInstancing()
{
- // test execution
+ // act
var html = new HtmlElementFieldLabel("abcdef");
Assert.Equal(@"", html.Trim());
@@ -38,7 +38,7 @@ public void TextAtInstancing()
[Fact]
public void TextAtProperty()
{
- // test execution
+ // act
var html = new HtmlElementFieldLabel
{
Text = "abcdef"
@@ -53,7 +53,7 @@ public void TextAtProperty()
[Fact]
public void TextAtHtmlText()
{
- // test execution
+ // act
var html = new HtmlElementFieldLabel(new HtmlText("abc"), new HtmlText("def"));
Assert.Equal(@"", html.Trim());
@@ -65,7 +65,7 @@ public void TextAtHtmlText()
[Fact]
public void TextWithId()
{
- // test execution
+ // act
var html = new HtmlElementFieldLabel()
{
Id = "identity"
@@ -80,7 +80,7 @@ public void TextWithId()
[Fact]
public void Inline()
{
- // test execution
+ // act
var html = new HtmlElementFieldLabel();
Assert.False(html.Inline);
@@ -92,7 +92,7 @@ public void Inline()
[Fact]
public void CloseTag()
{
- // test execution
+ // act
var html = new HtmlElementFieldLabel();
Assert.True(html.CloseTag);
@@ -104,7 +104,7 @@ public void CloseTag()
[Fact]
public void Class()
{
- // test execution
+ // act
var html = new HtmlElementFieldLabel()
{
Class = "abc"
@@ -119,7 +119,7 @@ public void Class()
[Fact]
public void Style()
{
- // test execution
+ // act
var html = new HtmlElementFieldLabel()
{
Style = "abc"
diff --git a/src/WebExpress.WebCore.Test/Html/UnitTestHtmlElementMetadataBase.cs b/src/WebExpress.WebCore.Test/Html/UnitTestHtmlElementMetadataBase.cs
index 8a80013..67fdea8 100644
--- a/src/WebExpress.WebCore.Test/Html/UnitTestHtmlElementMetadataBase.cs
+++ b/src/WebExpress.WebCore.Test/Html/UnitTestHtmlElementMetadataBase.cs
@@ -14,10 +14,10 @@ public class UnitTestHtmlElementMetadataBase
[Fact]
public void Constructor()
{
- // preconditions
+ // arrange
var url = "https://example.com";
- // test execution
+ // act
var element = new HtmlElementMetadataBase(url);
// validation
@@ -32,10 +32,10 @@ public void Constructor()
[InlineData("https://example.com", "https://example.com")]
public void Href(string uri, string expected)
{
- // preconditions
+ // arrange
var element = new HtmlElementMetadataBase();
- // test execution
+ // act
element.Href = uri;
// validation
diff --git a/src/WebExpress.WebCore.Test/Html/UnitTestHtmlElementRootHtml.cs b/src/WebExpress.WebCore.Test/Html/UnitTestHtmlElementRootHtml.cs
index d5115e3..c167356 100644
--- a/src/WebExpress.WebCore.Test/Html/UnitTestHtmlElementRootHtml.cs
+++ b/src/WebExpress.WebCore.Test/Html/UnitTestHtmlElementRootHtml.cs
@@ -14,10 +14,10 @@ public class UnitTestHtmlElementRootHtml
[Fact]
public void HeadBase()
{
- // preconditions
+ // arrange
var url = "https://example.com";
- // test execution
+ // act
var element = new HtmlElementRootHtml();
element.Head.Base = url;
diff --git a/src/WebExpress.WebCore.Test/Html/UnitTestHtmlElementTextContentP.cs b/src/WebExpress.WebCore.Test/Html/UnitTestHtmlElementTextContentP.cs
index 555fdfa..1ec474d 100644
--- a/src/WebExpress.WebCore.Test/Html/UnitTestHtmlElementTextContentP.cs
+++ b/src/WebExpress.WebCore.Test/Html/UnitTestHtmlElementTextContentP.cs
@@ -14,7 +14,7 @@ public class UnitTestHtmlElementTextContentP
[Fact]
public void Empty()
{
- // test execution
+ // act
var html = new HtmlElementTextContentP();
Assert.Equal(@"", html.Trim());
@@ -26,7 +26,7 @@ public void Empty()
[Fact]
public void TextAtInstancing()
{
- // test execution
+ // act
var html = new HtmlElementTextContentP("abcdef");
Assert.Equal(@"abcdef
", html.Trim());
@@ -38,7 +38,7 @@ public void TextAtInstancing()
[Fact]
public void TextAtProperty()
{
- // test execution
+ // act
var html = new HtmlElementTextContentP
{
Text = "abcdef"
@@ -53,7 +53,7 @@ public void TextAtProperty()
[Fact]
public void TextAtHtmlText()
{
- // test execution
+ // act
var html = new HtmlElementTextContentP(new HtmlText("abc"), new HtmlText("def"));
var str = html.ToString();
@@ -66,7 +66,7 @@ public void TextAtHtmlText()
[Fact]
public void TextWithId()
{
- // test execution
+ // act
var html = new HtmlElementTextContentP()
{
Id = "identity"
@@ -81,7 +81,7 @@ public void TextWithId()
[Fact]
public void Inline()
{
- // test execution
+ // act
var html = new HtmlElementTextContentP();
Assert.False(html.Inline);
@@ -93,7 +93,7 @@ public void Inline()
[Fact]
public void CloseTag()
{
- // test execution
+ // act
var html = new HtmlElementTextContentP();
Assert.True(html.CloseTag);
@@ -105,7 +105,7 @@ public void CloseTag()
[Fact]
public void Class()
{
- // test execution
+ // act
var html = new HtmlElementTextContentP()
{
Class = "abc"
@@ -120,7 +120,7 @@ public void Class()
[Fact]
public void Style()
{
- // test execution
+ // act
var html = new HtmlElementTextContentP()
{
Style = "abc"
diff --git a/src/WebExpress.WebCore.Test/Html/UnitTestHtmlImage.cs b/src/WebExpress.WebCore.Test/Html/UnitTestHtmlImage.cs
index f5c9d85..5679f85 100644
--- a/src/WebExpress.WebCore.Test/Html/UnitTestHtmlImage.cs
+++ b/src/WebExpress.WebCore.Test/Html/UnitTestHtmlImage.cs
@@ -14,7 +14,7 @@ public class UnitTestHtmlImage
[Fact]
public void Empty()
{
- // test execution
+ // act
var html = new HtmlElementMultimediaImg();
Assert.Equal(@"
", html.ToString().Trim());
diff --git a/src/WebExpress.WebCore.Test/Html/UnitTestHtmlText.cs b/src/WebExpress.WebCore.Test/Html/UnitTestHtmlText.cs
index 4d499af..a89b3b4 100644
--- a/src/WebExpress.WebCore.Test/Html/UnitTestHtmlText.cs
+++ b/src/WebExpress.WebCore.Test/Html/UnitTestHtmlText.cs
@@ -14,7 +14,7 @@ public class UnitTestHtmlText
[Fact]
public void Empty()
{
- // test execution
+ // act
var html = new HtmlText();
Assert.Null(html.Value);
@@ -26,7 +26,7 @@ public void Empty()
[Fact]
public void TextAtInstancing()
{
- // test execution
+ // act
var html = new HtmlText("abcdef");
Assert.Equal(@"abcdef", html.Value);
@@ -38,7 +38,7 @@ public void TextAtInstancing()
[Fact]
public void TextAtProperty()
{
- // test execution
+ // act
var html = new HtmlText
{
Value = "abcdef"
diff --git a/src/WebExpress.WebCore.Test/Html/UnitTestRandomId.cs b/src/WebExpress.WebCore.Test/Html/UnitTestRandomId.cs
new file mode 100644
index 0000000..6152894
--- /dev/null
+++ b/src/WebExpress.WebCore.Test/Html/UnitTestRandomId.cs
@@ -0,0 +1,100 @@
+using System.Collections.Concurrent;
+using WebExpress.WebCore.WebHtml;
+
+namespace WebExpress.WebCore.Test.Html
+{
+ ///
+ /// Unit tests for the RandomId class.
+ ///
+ [Collection("NonParallelTests")]
+ public class UnitTestRandomId
+ {
+ ///
+ /// Tests the create method.
+ ///
+ [Fact]
+ public void CreateDifferent()
+ {
+ // act
+ var id1 = RandomId.Create();
+ var id2 = RandomId.Create();
+
+ // validation
+ Assert.NotEqual(id1, id2);
+ }
+
+ ///
+ /// Tests the create method.
+ ///
+ [Fact]
+ public void Prefix()
+ {
+ // act
+ var id = RandomId.Create();
+
+ // validation
+ Assert.StartsWith("id_", id);
+ }
+
+ ///
+ /// Tests the create method.
+ ///
+ [Fact]
+ public void Length()
+ {
+ // act
+ var id = RandomId.Create();
+
+ // validation
+ Assert.Equal("id_".Length + 32, id.Length);
+ }
+
+ ///
+ /// Tests the create method.
+ ///
+ [Fact]
+ public void HexCharacters()
+ {
+ // act
+ var id = RandomId.Create();
+
+ // validation
+ var hex = id.Substring("id_".Length);
+ Assert.Matches("^[0-9A-F]+$", hex);
+ }
+
+ ///
+ /// Tests the create method.
+ ///
+ [Fact]
+ public void ThreadSafe()
+ {
+ // arrange
+ var results = new ConcurrentBag();
+
+ Parallel.For(0, 5000, _ =>
+ {
+ // act
+ results.Add(RandomId.Create());
+ });
+
+ // validation
+ var distinct = results.Distinct().Count();
+
+ Assert.Equal(results.Count, distinct);
+ }
+
+ ///
+ /// Tests the create method.
+ ///
+ [Fact]
+ public void NotNullOrEmpty()
+ {
+ // act
+ var id = RandomId.Create();
+
+ // validation
+ Assert.False(string.IsNullOrWhiteSpace(id));
+ }
+ }
+}
diff --git a/src/WebExpress.WebCore.Test/Manager/UnitTestApplication.cs b/src/WebExpress.WebCore.Test/Manager/UnitTestApplicationManager.cs
similarity index 87%
rename from src/WebExpress.WebCore.Test/Manager/UnitTestApplication.cs
rename to src/WebExpress.WebCore.Test/Manager/UnitTestApplicationManager.cs
index db76fe1..d7e011b 100644
--- a/src/WebExpress.WebCore.Test/Manager/UnitTestApplication.cs
+++ b/src/WebExpress.WebCore.Test/Manager/UnitTestApplicationManager.cs
@@ -9,7 +9,7 @@ namespace WebExpress.WebCore.Test.Manager
/// Test the application manager.
///
[Collection("NonParallelTests")]
- public class UnitTestApplication
+ public class UnitTestApplicationManager
{
///
/// Test the register function of the application manager.
@@ -17,13 +17,14 @@ public class UnitTestApplication
[Fact]
public void Register()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateComponentHubMock();
var pluginManager = componentHub.PluginManager as PluginManager;
- // test execution
+ // act
pluginManager.Register();
+ // validation
Assert.Equal(3, componentHub.ApplicationManager.Applications.Count());
Assert.Equal("webexpress.webcore.test.testapplicationa", componentHub.ApplicationManager.GetApplications(typeof(TestApplicationA)).FirstOrDefault()?.ApplicationId);
Assert.Equal("webexpress.webcore.test.testapplicationb", componentHub.ApplicationManager.GetApplications(typeof(TestApplicationB)).FirstOrDefault()?.ApplicationId);
@@ -36,19 +37,20 @@ public void Register()
[Fact]
public void Remove()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var applicationManager = componentHub.ApplicationManager as ApplicationManager;
var plugin = componentHub.PluginManager.GetPlugin(typeof(TestPlugin));
- // test execution
+ // act
applicationManager.Remove(plugin);
- Assert.Empty(componentHub.ApplicationManager.Applications);
+ // validation
+ Assert.Empty(applicationManager.Applications);
}
///
- /// Test the name property of the application.
+ /// Test the id property of the application.
///
[Theory]
[InlineData(typeof(TestApplicationA), "webexpress.webcore.test.testapplicationa")]
@@ -56,11 +58,11 @@ public void Remove()
[InlineData(typeof(TestApplicationC), "webexpress.webcore.test.testapplicationc")]
public void Id(Type applicationType, string id)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
- // test execution
+ // act
Assert.Equal(id, application.ApplicationId);
}
@@ -73,11 +75,11 @@ public void Id(Type applicationType, string id)
[InlineData(typeof(TestApplicationC), "TestApplicationC")]
public void Name(Type applicationType, string name)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
- // test execution
+ // act
Assert.Equal(name, application.ApplicationName);
}
@@ -90,11 +92,11 @@ public void Name(Type applicationType, string name)
[InlineData(typeof(TestApplicationC), "application.description")]
public void Description(Type applicationType, string description)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
- // test execution
+ // act
Assert.Equal(description, application.Description);
}
@@ -107,11 +109,11 @@ public void Description(Type applicationType, string description)
[InlineData(typeof(TestApplicationC), "/server/assets/img/Logo.png")]
public void Icon(Type applicationType, string icon)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
- // test execution
+ // act
Assert.Equal(icon, application.Icon.ToString());
}
@@ -124,11 +126,11 @@ public void Icon(Type applicationType, string icon)
[InlineData(typeof(TestApplicationC), "/server")]
public void ContextPath(Type applicationType, string contextPath)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
- // test execution
+ // act
Assert.Equal(contextPath, application.Route.ToString());
}
@@ -138,15 +140,15 @@ public void ContextPath(Type applicationType, string contextPath)
[Theory]
[InlineData(typeof(TestApplicationA), "/asseta")]
[InlineData(typeof(TestApplicationB), "/assetb")]
- [InlineData(typeof(TestApplicationC), "/")]
+ [InlineData(typeof(TestApplicationC), "*/")]
public void AssetPath(Type applicationType, string assetPath)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
- // test execution
- Assert.Equal(assetPath, application.AssetPath);
+ // act
+ AssertExtensions.EqualWithPlaceholders(assetPath, application.AssetPath);
}
///
@@ -155,15 +157,15 @@ public void AssetPath(Type applicationType, string assetPath)
[Theory]
[InlineData(typeof(TestApplicationA), "/dataa")]
[InlineData(typeof(TestApplicationB), "/datab")]
- [InlineData(typeof(TestApplicationC), "/")]
+ [InlineData(typeof(TestApplicationC), "*/")]
public void DataPath(Type applicationType, string dataPath)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
- // test execution
- Assert.Equal(dataPath, application.DataPath);
+ // act
+ AssertExtensions.EqualWithPlaceholders(dataPath, application.DataPath);
}
///
@@ -172,10 +174,10 @@ public void DataPath(Type applicationType, string dataPath)
[Fact]
public void IsIComponentManager()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.True(typeof(IComponentManager).IsAssignableFrom(componentHub.ApplicationManager.GetType()));
}
@@ -185,10 +187,10 @@ public void IsIComponentManager()
[Fact]
public void IsIContext()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
foreach (var application in componentHub.ApplicationManager.Applications)
{
Assert.True(typeof(IContext).IsAssignableFrom(application.GetType()), $"Application context {application.GetType().Name} does not implement IContext.");
diff --git a/src/WebExpress.WebCore.Test/Manager/UnitTestAssetManager.cs b/src/WebExpress.WebCore.Test/Manager/UnitTestAssetManager.cs
index 1974d85..b150178 100644
--- a/src/WebExpress.WebCore.Test/Manager/UnitTestAssetManager.cs
+++ b/src/WebExpress.WebCore.Test/Manager/UnitTestAssetManager.cs
@@ -19,10 +19,10 @@ public class UnitTestAssetManager
[Fact]
public void Register()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.Equal(12, componentHub.AssetManager.Assets.Count());
}
@@ -32,12 +32,12 @@ public void Register()
[Fact]
public void Remove()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var plugin = componentHub.PluginManager.GetPlugin(typeof(TestPlugin));
var resourceManager = componentHub.AssetManager as AssetManager;
- // test execution
+ // act
resourceManager.Remove(plugin);
Assert.Empty(componentHub.AssetManager.Assets);
@@ -59,12 +59,12 @@ public void Remove()
[InlineData(typeof(TestApplicationC), "webexpress.webcore.test.js.myjavascript.mini.js")]
public void Id(Type applicationType, string id)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType)?.FirstOrDefault();
var asset = componentHub.AssetManager.GetAssets(application)?.FirstOrDefault(x => x.EndpointId.ToString() == id);
- // test execution
+ // act
Assert.Equal(id, asset?.EndpointId.ToString());
}
@@ -84,13 +84,13 @@ public void Id(Type applicationType, string id)
[InlineData(typeof(TestApplicationC), "/server/assets/js/myjavascript.mini.js")]
public void Uri(Type applicationType, string route)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType)?.FirstOrDefault();
var asset = componentHub.AssetManager.GetAssets(application)?
.FirstOrDefault(x => x.Route.ToString() == route);
- // test execution
+ // act
Assert.Equal(route, asset?.Route.ToString());
}
@@ -110,14 +110,14 @@ public void Uri(Type applicationType, string route)
[InlineData("http://localhost:8080/server/assets/js/myjavascript.mini.js", "js/myjavascript.mini.js")]
public void Request(string uri, string resource)
{
- // preconditions
+ // arrange
var embeddedResource = UnitTestFixture.GetEmbeddedResource(resource);
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var context = UnitTestFixture.CreateHttpContextMock();
var httpServerContext = UnitTestFixture.CreateHttpServerContextMock();
componentHub.SitemapManager.Refresh();
- // test execution
+ // act
var searchResult = componentHub.SitemapManager.SearchResource(new System.Uri(uri), new SearchContext()
{
HttpServerContext = httpServerContext,
@@ -127,7 +127,7 @@ public void Request(string uri, string resource)
var response = componentHub
.EndpointManager
- .HandleRequest(UnitTestFixture.CrerateRequestMock("", uri), searchResult.EndpointContext);
+ .HandleRequest(UnitTestFixture.CreateRequestMock("", uri), searchResult.EndpointContext);
Assert.Equal($"webexpress.webcore.test.{resource.Replace('/', '.')}", searchResult?.EndpointContext?.EndpointId.ToString());
Assert.IsNotType(response);
@@ -140,10 +140,10 @@ public void Request(string uri, string resource)
[Fact]
public void IsIComponentManager()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.True(typeof(IComponentManager).IsAssignableFrom(componentHub.AssetManager.GetType()));
}
@@ -153,10 +153,10 @@ public void IsIComponentManager()
[Fact]
public void IsIContext()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
foreach (var asset in componentHub.AssetManager.Assets)
{
Assert.True(typeof(IContext).IsAssignableFrom(asset.GetType()), $"Asset context {asset.GetType().Name} does not implement IContext.");
diff --git a/src/WebExpress.WebCore.Test/Manager/UnitTestComponentManager.cs b/src/WebExpress.WebCore.Test/Manager/UnitTestComponentManager.cs
index d0ebaaf..52a5a9a 100644
--- a/src/WebExpress.WebCore.Test/Manager/UnitTestComponentManager.cs
+++ b/src/WebExpress.WebCore.Test/Manager/UnitTestComponentManager.cs
@@ -14,10 +14,10 @@ public class UnitTestComponentManager
[Fact]
public void PluginManager()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateComponentHubMock();
- // test execution
+ // act
Assert.NotNull(componentHub.PluginManager);
}
@@ -27,10 +27,10 @@ public void PluginManager()
[Fact]
public void ApplicationManager()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateComponentHubMock();
- // test execution
+ // act
Assert.NotNull(componentHub.ApplicationManager);
}
}
diff --git a/src/WebExpress.WebCore.Test/Manager/UnitTestEventManager.cs b/src/WebExpress.WebCore.Test/Manager/UnitTestEventManager.cs
index 9c68326..09573b2 100644
--- a/src/WebExpress.WebCore.Test/Manager/UnitTestEventManager.cs
+++ b/src/WebExpress.WebCore.Test/Manager/UnitTestEventManager.cs
@@ -16,10 +16,10 @@ public class UnitTestEventManager
[Fact]
public void Register()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.Equal(6, componentHub.EventManager.EventHandlers.Count());
}
@@ -29,12 +29,12 @@ public void Register()
[Fact]
public void Remove()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var eventManager = componentHub.EventManager as EventManager;
var plugin = componentHub.PluginManager.GetPlugin(typeof(TestPlugin));
- // test execution
+ // act
eventManager.Remove(plugin);
Assert.Empty(componentHub.EventManager.EventHandlers);
@@ -46,10 +46,10 @@ public void Remove()
[Fact]
public void IsIComponentManager()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.True(typeof(IComponentManager).IsAssignableFrom(componentHub.EventManager.GetType()));
}
@@ -63,14 +63,14 @@ public void IsIComponentManager()
[InlineData(typeof(TestApplicationB), typeof(TestEventB), "webexpress.webcore.test.testeventhandlerb")]
public void Id(Type applicationType, Type eventType, string id)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
- // test execution
+ // act
var eventHandlers = componentHub.EventManager.GetEventHandlers(application, eventType);
- if (id == null)
+ if (id is null)
{
Assert.Empty(eventHandlers);
return;
@@ -89,14 +89,14 @@ public void Id(Type applicationType, Type eventType, string id)
[InlineData(typeof(TestApplicationB), typeof(TestEventB), "webexpress.webcore.test.testeventb")]
public void EventId(Type applicationType, Type eventType, string id)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
- // test execution
+ // act
var eventHandlers = componentHub.EventManager.GetEventHandlers(application, eventType);
- if (id == null)
+ if (id is null)
{
Assert.Empty(eventHandlers);
return;
@@ -111,11 +111,11 @@ public void EventId(Type applicationType, Type eventType, string id)
[Fact]
public void RaiseEventA1()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplication();
- // test execution
+ // act
var eventArgument = new TestEventArgument() { TestProperty = false };
componentHub.EventManager.RaiseEvent(application, this, eventArgument);
@@ -129,11 +129,11 @@ public void RaiseEventA1()
[Fact]
public void RaiseEventB1()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplication();
- // test execution
+ // act
var eventArgument = new TestEventArgument() { TestProperty = false };
componentHub.EventManager.RaiseEvent(application, this, eventArgument);
diff --git a/src/WebExpress.WebCore.Test/Manager/UnitTestFragmentManager.cs b/src/WebExpress.WebCore.Test/Manager/UnitTestFragmentManager.cs
index 35df62c..66859b6 100644
--- a/src/WebExpress.WebCore.Test/Manager/UnitTestFragmentManager.cs
+++ b/src/WebExpress.WebCore.Test/Manager/UnitTestFragmentManager.cs
@@ -19,10 +19,10 @@ public class UnitTestFragmentManager
[Fact]
public void Register()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.Equal(15, componentHub.FragmentManager.Fragments.Count());
}
@@ -32,14 +32,15 @@ public void Register()
[Fact]
public void Remove()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var fragmentManager = componentHub.FragmentManager as FragmentManager;
var plugin = componentHub.PluginManager.GetPlugin(typeof(TestPlugin));
- // test execution
+ // act
fragmentManager.Remove(plugin);
+ // validation
Assert.Empty(componentHub.FragmentManager.Fragments);
}
@@ -49,10 +50,10 @@ public void Remove()
[Fact]
public void IsIComponentManager()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.True(typeof(IComponentManager).IsAssignableFrom(componentHub.EventManager.GetType()));
}
@@ -71,19 +72,20 @@ public void IsIComponentManager()
[InlineData(typeof(TestApplicationC), typeof(TestFragmentC), "webexpress.webcore.test.testfragmentc")]
public void Id(Type applicationType, Type fragmentType, string id)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
- // test execution
+ // act
var fragment = componentHub.FragmentManager.GetFragments(application, fragmentType);
- if (id == null)
+ if (id is null)
{
Assert.Empty(fragment);
return;
}
+ // validation
Assert.Contains(id, fragment.Select(x => x.FragmentId?.ToString()));
}
@@ -98,14 +100,39 @@ public void Id(Type applicationType, Type fragmentType, string id)
[InlineData(typeof(TestApplicationB), typeof(About), 1)]
public void GetFragments(Type applicationType, Type scopeType, int count)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
var renderContext = UnitTestFixture.CrerateRenderContextMock(application, [scopeType]);
- // test execution
+ // act
var fragments = componentHub.FragmentManager.GetFragments(application, renderContext?.PageContext?.Scopes).ToList();
+ // validation
+ Assert.NotNull(fragments);
+ Assert.Equal(count, fragments.Count);
+ }
+
+ ///
+ /// Test the get fragment function of the fragment.
+ ///
+ [Theory]
+ [InlineData(typeof(TestApplicationA), typeof(IScope), 0)]
+ [InlineData(typeof(TestApplicationA), typeof(TestScopeA), 1)]
+ [InlineData(typeof(TestApplicationA), typeof(About), 1)]
+ [InlineData(typeof(TestApplicationB), typeof(IScope), 0)]
+ [InlineData(typeof(TestApplicationB), typeof(About), 1)]
+ public void GetFragmentsBase(Type applicationType, Type scopeType, int count)
+ {
+ // arrange
+ var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
+ var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
+ var renderContext = UnitTestFixture.CrerateRenderContextMock(application, [scopeType]);
+
+ // act
+ var fragments = componentHub.FragmentManager.GetFragments(application, renderContext?.PageContext?.Scopes).ToList();
+
+ // validation
Assert.NotNull(fragments);
Assert.Equal(count, fragments.Count);
}
@@ -121,15 +148,16 @@ public void GetFragments(Type applicationType, Type scopeType, int count)
[InlineData(typeof(TestApplicationA), typeof(TestSectionA), typeof(TestScopeD), true)]
public void Render(Type applicationType, Type sectionType, Type scopeType, bool empty)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
var renderContext = UnitTestFixture.CrerateRenderContextMock(application, [scopeType]);
var visualTree = new VisualTree();
- // test execution
+ // act
var html = componentHub.FragmentManager.Render(renderContext, visualTree, sectionType);
+ // validation
Assert.NotNull(html);
if (!empty)
diff --git a/src/WebExpress.WebCore.Test/Manager/UnitTestIdentityManager.cs b/src/WebExpress.WebCore.Test/Manager/UnitTestIdentityManager.cs
index 9f381a0..6e1b337 100644
--- a/src/WebExpress.WebCore.Test/Manager/UnitTestIdentityManager.cs
+++ b/src/WebExpress.WebCore.Test/Manager/UnitTestIdentityManager.cs
@@ -18,10 +18,10 @@ public class UnitTestIdentityManager
[Fact]
public void Register()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.Equal(9, componentHub.IdentityManager.Permissions.Count());
Assert.Equal(6, componentHub.IdentityManager.Policies.Count());
}
@@ -32,12 +32,12 @@ public void Register()
[Fact]
public void Remove()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var plugin = componentHub.PluginManager.GetPlugin(typeof(TestPlugin));
var identityManager = componentHub.IdentityManager as IdentityManager;
- // test execution
+ // act
identityManager.Remove(plugin);
Assert.Empty(componentHub.IdentityManager.Permissions);
@@ -50,10 +50,10 @@ public void Remove()
[Fact]
public void IsIComponentManager()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.True(typeof(IComponentManager).IsAssignableFrom(componentHub.IdentityManager.GetType()));
}
@@ -72,13 +72,13 @@ public void IsIComponentManager()
[InlineData(typeof(TestApplicationA), "Charlie", typeof(TestIdentityPermissionC), false)]
public void CheckAccessIdentity(Type application, string identityName, Type permission, bool expected)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var identityManager = componentHub.IdentityManager as IdentityManager;
var applicationContext = componentHub.ApplicationManager.GetApplications(application).FirstOrDefault();
var identity = MockIdentityFactory.GetIdentity(identityName);
- // test execution
+ // act
var access = identityManager.CheckAccess(applicationContext, identity, permission);
Assert.Equal(expected, access);
@@ -99,13 +99,13 @@ public void CheckAccessIdentity(Type application, string identityName, Type perm
[InlineData(typeof(TestApplicationA), "Guests", typeof(TestIdentityPermissionC), false)]
public void CheckAccessGroup(Type application, string groupName, Type permission, bool expected)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var identityManager = componentHub.IdentityManager as IdentityManager;
var applicationContext = componentHub.ApplicationManager.GetApplications(application).FirstOrDefault();
var group = MockIdentityFactory.GetIdentityGroup(groupName);
- // test execution
+ // act
var access = identityManager.CheckAccess(applicationContext, group, permission);
Assert.Equal(expected, access);
@@ -123,12 +123,12 @@ public void CheckAccessGroup(Type application, string groupName, Type permission
[InlineData(typeof(TestApplicationA), typeof(TestIdentityPolicyB), typeof(TestIdentityPermissionC), false)]
public void CheckAccess(Type application, Type policy, Type permission, bool expected)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var identityManager = componentHub.IdentityManager as IdentityManager;
var applicationContext = componentHub.ApplicationManager.GetApplications(application).FirstOrDefault();
- // test execution
+ // act
var access = identityManager.CheckAccess(applicationContext, policy, permission);
Assert.Equal(expected, access);
@@ -142,16 +142,16 @@ public void CheckAccess(Type application, Type policy, Type permission, bool exp
[InlineData("Alice", "123", false)]
public void Login(string identityName, string password, bool expected)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var identityManager = componentHub.IdentityManager as IdentityManager;
- var request = UnitTestFixture.CrerateRequestMock();
+ var request = UnitTestFixture.CreateRequestMock();
var identity = MockIdentityFactory.GetIdentity(identityName);
var securePassword = new SecureString();
password.ToList().ForEach(x => securePassword.AppendChar(x));
securePassword.MakeReadOnly();
- // test execution
+ // act
var res = identityManager.Login(request, identity, securePassword);
Assert.Equal(expected, res);
@@ -166,17 +166,17 @@ public void Login(string identityName, string password, bool expected)
[InlineData("Charlie", "abc")]
public void Logout(string identityName, string password)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var identityManager = componentHub.IdentityManager as IdentityManager;
- var request = UnitTestFixture.CrerateRequestMock();
+ var request = UnitTestFixture.CreateRequestMock();
var identity = MockIdentityFactory.GetIdentity(identityName);
var securePassword = new SecureString();
password.ToList().ForEach(x => securePassword.AppendChar(x));
securePassword.MakeReadOnly();
identityManager.Login(request, identity, securePassword);
- // test execution
+ // act
identityManager.Logout(request);
var res = identityManager.GetCurrentIdentity(request);
@@ -192,17 +192,17 @@ public void Logout(string identityName, string password)
[InlineData("Charlie", "abc")]
public void GetCurrentIdentity(string identityName, string password)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var identityManager = componentHub.IdentityManager as IdentityManager;
- var request = UnitTestFixture.CrerateRequestMock();
+ var request = UnitTestFixture.CreateRequestMock();
var identity = MockIdentityFactory.GetIdentity(identityName);
var securePassword = new SecureString();
password.ToList().ForEach(x => securePassword.AppendChar(x));
securePassword.MakeReadOnly();
identityManager.Login(request, identity, securePassword);
- // test execution
+ // act
var res = identityManager.GetCurrentIdentity(request);
Assert.Equal(identity, res);
diff --git a/src/WebExpress.WebCore.Test/Manager/UnitTestIncludeManager.cs b/src/WebExpress.WebCore.Test/Manager/UnitTestIncludeManager.cs
index c194bdd..bf1755e 100644
--- a/src/WebExpress.WebCore.Test/Manager/UnitTestIncludeManager.cs
+++ b/src/WebExpress.WebCore.Test/Manager/UnitTestIncludeManager.cs
@@ -16,10 +16,10 @@ public class UnitTestIncludeManager
[Fact]
public void Register()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.Equal(12, componentHub.IncludeManager.Includes.Count());
}
@@ -29,12 +29,12 @@ public void Register()
[Fact]
public void Remove()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var plugin = componentHub.PluginManager.GetPlugin(typeof(TestPlugin));
var includeManager = componentHub.IncludeManager as IncludeManager;
- // test execution
+ // act
includeManager.Remove(plugin);
// validation
@@ -59,12 +59,12 @@ public void Remove()
[InlineData(typeof(TestApplicationC), typeof(TestIncludeCssB), "webexpress.webcore.test.testincludecssb")]
public void Id(Type applicationType, Type includeType, string expected)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType)?.FirstOrDefault();
var include = componentHub.IncludeManager.GetIncludes(application, includeType)?.FirstOrDefault();
- // test execution
+ // act
var id = include?.IncludeId.ToString();
// validation
@@ -89,12 +89,12 @@ public void Id(Type applicationType, Type includeType, string expected)
[InlineData(typeof(TestApplicationC), typeof(TestIncludeCssB), "/myX.css;/myY.css;/myZ.css")]
public void Files(Type applicationType, Type resourceType, string expected)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType)?.FirstOrDefault();
var include = componentHub.IncludeManager.GetIncludes(application, resourceType)?.FirstOrDefault();
- // test execution
+ // act
var files = include.Files.Select(x => x.FileName);
// validation
@@ -119,12 +119,12 @@ public void Files(Type applicationType, Type resourceType, string expected)
[InlineData(typeof(TestApplicationC), typeof(TestIncludeCssB), "StyleSheet;StyleSheet;StyleSheet")]
public void FileType(Type applicationType, Type resourceType, string expected)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType)?.FirstOrDefault();
var include = componentHub.IncludeManager.GetIncludes(application, resourceType)?.FirstOrDefault();
- // test execution
+ // act
var files = include.Files.Select(x => x.Type);
// validation
@@ -137,10 +137,10 @@ public void FileType(Type applicationType, Type resourceType, string expected)
[Fact]
public void IsIComponentManager()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.True(typeof(IComponentManager).IsAssignableFrom(componentHub.IncludeManager.GetType()));
}
@@ -150,10 +150,10 @@ public void IsIComponentManager()
[Fact]
public void IsIContext()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
foreach (var include in componentHub.IncludeManager.Includes)
{
Assert.True(typeof(IContext).IsAssignableFrom(include.GetType()), $"Include context '{include.GetType().Name}' does not implement IContext.");
diff --git a/src/WebExpress.WebCore.Test/Manager/UnitTestInternationalization.cs b/src/WebExpress.WebCore.Test/Manager/UnitTestInternationalization.cs
index 9b3247c..f33ce9d 100644
--- a/src/WebExpress.WebCore.Test/Manager/UnitTestInternationalization.cs
+++ b/src/WebExpress.WebCore.Test/Manager/UnitTestInternationalization.cs
@@ -18,11 +18,11 @@ public class UnitTestInternationalization
[Fact]
public void Register()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateComponentHubMock();
var pluginManager = componentHub.PluginManager as PluginManager;
- // test execution
+ // act
pluginManager.Register();
Assert.Equal("This is a test", I18N.Translate("webexpress.webcore.test:unit.test.message"));
@@ -34,12 +34,12 @@ public void Register()
[Fact]
public void Remove()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var internationalizationManager = componentHub.InternationalizationManager as InternationalizationManager;
var plugin = componentHub.PluginManager.GetPlugin(typeof(TestPlugin));
- // test execution
+ // act
internationalizationManager.Remove(plugin);
Assert.Equal("webexpress.webcore.test:unit.test.message", I18N.Translate("webexpress.webcore.test:unit.test.message"));
@@ -51,10 +51,10 @@ public void Remove()
[Fact]
public void GetDefaultCulture()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.Equal(CultureInfo.GetCultureInfo("en"), InternationalizationManager.DefaultCulture);
}
@@ -72,52 +72,51 @@ public void GetDefaultCulture()
[InlineData("non.existent.key", "non.existent.key", "de")]
public void Translate(string key, string excepted, string cultureName = null, string pluginID = null, params object[] param)
{
- // preconditions
+ // arrange
UnitTestFixture.CreateAndRegisterComponentHubMock();
- if (cultureName == null && !param.Any())
+ if (cultureName is null && param.Length == 0)
{
- // test execution
+ // act
var result = I18N.Translate(key);
Assert.Equal(excepted, result);
}
- if (cultureName == null && param.Any())
+ if (cultureName is null && param.Length != 0)
{
- // test execution
+ // act
var result = I18N.Translate(key, param);
Assert.Equal(excepted, result);
}
- if (cultureName != null && pluginID == null && !param.Any())
+ if (cultureName is not null && pluginID is null && param.Length == 0)
{
- // test execution
+ // act
var result = I18N.Translate(CultureInfo.GetCultureInfo(cultureName), key);
Assert.Equal(excepted, result);
}
- if (cultureName != null && pluginID == null && param.Any())
+ if (cultureName is not null && pluginID is null && param.Length != 0)
{
- // test execution
+ // act
var result = I18N.Translate(CultureInfo.GetCultureInfo(cultureName), key, param);
Assert.Equal(excepted, result);
}
- if (cultureName != null && pluginID != null && !param.Any())
+ if (cultureName is not null && pluginID is not null && param.Length == 0)
{
- // test execution
+ // act
var result = I18N.Translate(CultureInfo.GetCultureInfo(cultureName), pluginID, key);
Assert.Equal(excepted, result);
}
- if (cultureName != null && pluginID != null && param.Any())
+ if (cultureName is not null && pluginID is not null && param.Length != 0)
{
- // test execution
+ // act
var result = I18N.Translate(CultureInfo.GetCultureInfo(cultureName), pluginID, key, param);
Assert.Equal(excepted, result);
}
-
}
///
@@ -126,10 +125,10 @@ public void Translate(string key, string excepted, string cultureName = null, st
[Fact]
public void IsIComponentManager()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.True(typeof(IComponentManager).IsAssignableFrom(componentHub.InternationalizationManager.GetType()));
}
}
diff --git a/src/WebExpress.WebCore.Test/Manager/UnitTestJobManager.cs b/src/WebExpress.WebCore.Test/Manager/UnitTestJobManager.cs
index 3f4eb85..1d347c3 100644
--- a/src/WebExpress.WebCore.Test/Manager/UnitTestJobManager.cs
+++ b/src/WebExpress.WebCore.Test/Manager/UnitTestJobManager.cs
@@ -16,10 +16,10 @@ public class UnitTestJobManager
[Fact]
public void Register()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.Equal(3, componentHub.JobManager.Jobs.Count());
}
@@ -29,12 +29,12 @@ public void Register()
[Fact]
public void Remove()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var plugin = componentHub.PluginManager.GetPlugin(typeof(TestPlugin));
var jobManager = componentHub.JobManager as JobManager;
- // test execution
+ // act
jobManager.Remove(plugin);
Assert.Empty(componentHub.JobManager.Jobs);
@@ -46,10 +46,10 @@ public void Remove()
[Fact]
public void IsIComponentManager()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.True(typeof(IComponentManager).IsAssignableFrom(componentHub.ResourceManager.GetType()));
}
@@ -59,10 +59,10 @@ public void IsIComponentManager()
[Fact]
public void IsIContext()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
foreach (var job in componentHub.JobManager.Jobs)
{
Assert.True(typeof(IContext).IsAssignableFrom(job.GetType()), $"Job context {job.GetType().Name} does not implement IContext.");
@@ -79,12 +79,12 @@ public void IsIContext()
public void Id(Type applicationType, Type jobType, string id)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
var job = componentHub.JobManager.GetJob(application, jobType);
- // test execution
+ // act
Assert.Equal(id, job?.JobId.ToString());
}
@@ -97,12 +97,12 @@ public void Id(Type applicationType, Type jobType, string id)
[InlineData(typeof(TestApplicationC), typeof(TestJobA), 50, 8, 31, new[] { 1, 2 }, 0)]
public void Cron(Type applicationType, Type jobType, int minute, int hour, int day, int[] month, int weekday)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
var job = componentHub.JobManager.GetJob(application, jobType);
- // test execution
+ // act
Assert.Equal(minute, job?.Cron.Minute.FirstOrDefault() ?? -1);
Assert.Equal(hour, job?.Cron.Hour.FirstOrDefault() ?? -1);
Assert.Equal(day, job?.Cron.Day.FirstOrDefault() ?? -1);
diff --git a/src/WebExpress.WebCore.Test/Manager/UnitTestLogManager.cs b/src/WebExpress.WebCore.Test/Manager/UnitTestLogManager.cs
index 96f8c3d..2a94866 100644
--- a/src/WebExpress.WebCore.Test/Manager/UnitTestLogManager.cs
+++ b/src/WebExpress.WebCore.Test/Manager/UnitTestLogManager.cs
@@ -16,11 +16,11 @@ public class UnitTestLogManager
[Fact]
public void Register()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateComponentHubMock();
var logManager = componentHub.LogManager as LogManager;
- // test execution
+ // act
Assert.NotNull(logManager);
}
@@ -30,11 +30,11 @@ public void Register()
[Fact]
public void Remove()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateComponentHubMock();
var logManager = componentHub.LogManager as LogManager;
- // test execution
+ // act
Assert.NotNull(logManager);
}
@@ -44,11 +44,11 @@ public void Remove()
[Fact]
public void IsIComponentManager()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var logManager = componentHub.LogManager as LogManager;
- // test execution
+ // act
Assert.True(typeof(IComponentManager).IsAssignableFrom(logManager.GetType()));
}
}
diff --git a/src/WebExpress.WebCore.Test/Manager/UnitTestPackageManager.cs b/src/WebExpress.WebCore.Test/Manager/UnitTestPackageManager.cs
index 93ce7da..5814623 100644
--- a/src/WebExpress.WebCore.Test/Manager/UnitTestPackageManager.cs
+++ b/src/WebExpress.WebCore.Test/Manager/UnitTestPackageManager.cs
@@ -19,11 +19,11 @@ public class UnitTestPackageManager
[Fact]
public void Register()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateComponentHubMock();
var packageManager = componentHub.PackageManager as PackageManager;
- // test execution
+ // act
Assert.NotNull(packageManager);
}
@@ -33,11 +33,11 @@ public void Register()
[Fact]
public void Remove()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateComponentHubMock();
var packageManager = componentHub.PackageManager as PackageManager;
- // test execution
+ // act
Assert.NotNull(packageManager);
}
@@ -47,11 +47,11 @@ public void Remove()
[Fact]
public void IsIComponentManager()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var packageManager = componentHub.PackageManager as PackageManager;
- // test execution
+ // act
Assert.True(typeof(IComponentManager).IsAssignableFrom(packageManager.GetType()));
}
@@ -61,7 +61,7 @@ public void IsIComponentManager()
[Fact]
public void AddPackageEvent()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateComponentHubMock();
var packageManager = componentHub.PackageManager as PackageManager;
bool eventFired = false;
@@ -70,7 +70,7 @@ public void AddPackageEvent()
// create dummy package
var package = new PackageCatalogItem() { Id = "test", File = "test.wxp", State = PackageCatalogeItemState.Active };
- // test execution
+ // act
var method = typeof(PackageManager).GetMethod("OnAddPackage", BindingFlags.NonPublic | BindingFlags.Instance);
method.Invoke(packageManager, [package]);
@@ -84,7 +84,7 @@ public void AddPackageEvent()
[Fact]
public void RemovePackageEvent()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateComponentHubMock();
var packageManager = componentHub.PackageManager as PackageManager;
bool eventFired = false;
@@ -93,7 +93,7 @@ public void RemovePackageEvent()
// create dummy package
var package = new PackageCatalogItem() { Id = "test", File = "test.wxp", State = PackageCatalogeItemState.Active };
- // test execution
+ // act
var method = typeof(PackageManager).GetMethod("OnRemovePackage", BindingFlags.NonPublic | BindingFlags.Instance);
method.Invoke(packageManager, [package]);
@@ -106,7 +106,7 @@ public void RemovePackageEvent()
[Fact]
public void ScanDetectsNewPackage()
{
- // preconditions
+ // arrange
var httpServerContext = UnitTestFixture.CreateHttpServerContextMock();
var componentHub = UnitTestFixture.CreateComponentHubMock(httpServerContext);
var packageManager = componentHub.PackageManager as PackageManager;
@@ -131,7 +131,7 @@ public void ScanDetectsNewPackage()
");
}
- // test execution - scan should detect the new file
+ // act - scan should detect the new file
packageManager.Scan();
// validation
@@ -152,7 +152,7 @@ public void ScanDetectsNewPackage()
[Fact]
public void ScanDetectsRemovedPackage()
{
- // preconditions
+ // arrange
var httpServerContext = UnitTestFixture.CreateHttpServerContextMock();
var componentHub = UnitTestFixture.CreateComponentHubMock(httpServerContext);
var packageManager = componentHub.PackageManager as PackageManager;
@@ -183,7 +183,7 @@ public void ScanDetectsRemovedPackage()
// remove file and scan again
File.Delete(dummyFile);
- // test execution - scan should detect the removed file
+ // act - scan should detect the removed file
packageManager.Scan();
// validation
@@ -204,7 +204,7 @@ public void ScanDetectsRemovedPackage()
[Fact]
public void LoadPackageReadsSpec()
{
- // preconditions
+ // arrange
var httpServerContext = UnitTestFixture.CreateHttpServerContextMock();
var componentHub = UnitTestFixture.CreateComponentHubMock(httpServerContext);
var packageManager = componentHub.PackageManager as PackageManager;
@@ -231,7 +231,7 @@ public void LoadPackageReadsSpec()
// use private LoadPackage method via reflection
var method = typeof(PackageManager).GetMethod("LoadPackage", BindingFlags.NonPublic | BindingFlags.Instance);
- // test execution
+ // act
var result = method.Invoke(packageManager, [dummyFile]) as PackageCatalogItem;
// validation
diff --git a/src/WebExpress.WebCore.Test/Manager/UnitTestPageManager.cs b/src/WebExpress.WebCore.Test/Manager/UnitTestPageManager.cs
index fc39f30..cd35974 100644
--- a/src/WebExpress.WebCore.Test/Manager/UnitTestPageManager.cs
+++ b/src/WebExpress.WebCore.Test/Manager/UnitTestPageManager.cs
@@ -17,10 +17,10 @@ public class UnitTestPageManager
[Fact]
public void Register()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.Equal(33, componentHub.PageManager.Pages.Count());
}
@@ -30,12 +30,12 @@ public void Register()
[Fact]
public void Remove()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var plugin = componentHub.PluginManager.GetPlugin(typeof(TestPlugin));
var pageManager = componentHub.PageManager as PageManager;
- // test execution
+ // act
pageManager.Remove(plugin);
Assert.Empty(componentHub.PageManager.Pages);
@@ -58,12 +58,12 @@ public void Remove()
[InlineData(typeof(TestApplicationA), typeof(WWW.Products.Details.Index), "webexpress.webcore.test.www.products.details.index")]
public void Id(Type applicationType, Type pageType, string id)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType)?.FirstOrDefault();
var page = componentHub.PageManager.GetPages(pageType, application)?.FirstOrDefault();
- // test execution
+ // act
Assert.Equal(id, page.EndpointId.ToString());
}
@@ -83,12 +83,12 @@ public void Id(Type applicationType, Type pageType, string id)
public void Title(Type applicationType, Type resourceType, string title)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType)?.FirstOrDefault();
var page = componentHub.PageManager.GetPages(resourceType, application)?.FirstOrDefault();
- // test execution
+ // act
Assert.Equal(title, page.PageTitle);
}
@@ -107,12 +107,12 @@ public void Title(Type applicationType, Type resourceType, string title)
[InlineData(typeof(TestApplicationC), typeof(Contact), "/server/contact")]
public void RoutePath(Type applicationType, Type resourceType, string path)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType)?.FirstOrDefault();
var page = componentHub.PageManager.GetPages(resourceType, application)?.FirstOrDefault();
- // test execution
+ // act
Assert.Equal(path, page.Route.ToString());
}
@@ -122,10 +122,10 @@ public void RoutePath(Type applicationType, Type resourceType, string path)
[Fact]
public void IsIComponentManager()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.True(typeof(IComponentManager).IsAssignableFrom(componentHub.PageManager.GetType()));
}
@@ -135,10 +135,10 @@ public void IsIComponentManager()
[Fact]
public void IsIContext()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
foreach (var pages in componentHub.PageManager.Pages)
{
Assert.True(typeof(IContext).IsAssignableFrom(pages.GetType()), $"Page context {pages.GetType().Name} does not implement IContext.");
diff --git a/src/WebExpress.WebCore.Test/Manager/UnitTestPluginManager.cs b/src/WebExpress.WebCore.Test/Manager/UnitTestPluginManager.cs
index 2b1d5d7..815f347 100644
--- a/src/WebExpress.WebCore.Test/Manager/UnitTestPluginManager.cs
+++ b/src/WebExpress.WebCore.Test/Manager/UnitTestPluginManager.cs
@@ -16,11 +16,11 @@ public class UnitTestPluginManager
[Fact]
public void Register()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateComponentHubMock();
var pluginManager = componentHub.PluginManager as PluginManager;
- // test execution
+ // act
pluginManager.Register();
Assert.Single(componentHub.PluginManager.Plugins);
@@ -33,7 +33,7 @@ public void Register()
[Fact]
public void RegisterEvent()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateComponentHubMock();
var pluginManager = componentHub.PluginManager as PluginManager;
var i = 0;
@@ -41,7 +41,7 @@ public void RegisterEvent()
componentHub.PluginManager.AddPlugin += (s, e) => { i++; triggered = true; };
- // test execution
+ // act
pluginManager.Register();
Assert.Single(componentHub.PluginManager.Plugins);
@@ -56,13 +56,13 @@ public void RegisterEvent()
[Fact]
public void Remove()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateComponentHubMock();
var pluginManager = componentHub.PluginManager as PluginManager;
pluginManager.Register();
var plugin = componentHub.PluginManager.GetPlugin(typeof(TestPlugin));
- // test execution
+ // act
pluginManager.Remove(plugin);
Assert.Empty(componentHub.PluginManager.Plugins);
@@ -74,7 +74,7 @@ public void Remove()
[Fact]
public void RemoveEvent()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateComponentHubMock();
var pluginManager = componentHub.PluginManager as PluginManager;
var i = 1;
@@ -84,7 +84,7 @@ public void RemoveEvent()
pluginManager.Register();
var plugin = componentHub.PluginManager.GetPlugin(typeof(TestPlugin));
- // test execution
+ // act
pluginManager.Remove(plugin);
Assert.Empty(componentHub.PluginManager.Plugins);
@@ -98,10 +98,10 @@ public void RemoveEvent()
[Fact]
public void GetPluginById()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
var plugin = componentHub.PluginManager.GetPlugin("webexpress.webcore.test");
Assert.Equal("webexpress.webcore.test", plugin?.PluginId.ToString());
@@ -113,10 +113,10 @@ public void GetPluginById()
[Fact]
public void GetPluginByType()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
var plugin = componentHub.PluginManager.GetPlugin(typeof(TestPlugin));
Assert.Equal("webexpress.webcore.test", plugin?.PluginId.ToString());
@@ -128,11 +128,11 @@ public void GetPluginByType()
[Fact]
public void Id()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var plugin = componentHub.PluginManager.GetPlugin(typeof(TestPlugin));
- // test execution
+ // act
Assert.Equal(typeof(TestPlugin).Namespace.ToLower(), plugin.PluginId.ToString());
}
@@ -142,11 +142,11 @@ public void Id()
[Fact]
public void GetName()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var plugin = componentHub.PluginManager.GetPlugin(typeof(TestPlugin));
- // test execution
+ // act
Assert.Equal("TestPlugin", plugin.PluginName);
}
@@ -156,11 +156,11 @@ public void GetName()
[Fact]
public void GetDescription()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var plugin = componentHub.PluginManager.GetPlugin(typeof(TestPlugin));
- // test execution
+ // act
Assert.Equal("plugin.description", plugin.Description);
}
@@ -170,11 +170,11 @@ public void GetDescription()
[Fact]
public void GetIcon()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var plugin = componentHub.PluginManager.GetPlugin(typeof(TestPlugin));
- // test execution
+ // act
Assert.Equal("/server/assets/img/Logo.png", plugin.Icon.ToString());
}
@@ -188,13 +188,13 @@ public void GetIcon()
[InlineData(null, null)]
public void Boot(string pluginId, string expected)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateComponentHubMock();
var pluginManager = componentHub.PluginManager as PluginManager;
pluginManager.Register();
var plugin = componentHub.PluginManager.GetPlugin(pluginId);
- // test execution
+ // act
pluginManager.Boot(plugin);
Assert.Single(componentHub.PluginManager.Plugins);
@@ -211,13 +211,13 @@ public void Boot(string pluginId, string expected)
[InlineData(null, null)]
public void ShutDown(string pluginId, string expected)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateComponentHubMock();
var pluginManager = componentHub.PluginManager as PluginManager;
pluginManager.Register();
var plugin = componentHub.PluginManager.GetPlugin(pluginId);
- // test execution
+ // act
pluginManager.ShutDown(plugin);
Assert.Single(componentHub.PluginManager.Plugins);
@@ -230,11 +230,11 @@ public void ShutDown(string pluginId, string expected)
[Fact]
public void IsIComponentManager()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var pluginManager = componentHub.PluginManager as PluginManager;
- // test execution
+ // act
Assert.True(typeof(IComponentManager).IsAssignableFrom(pluginManager.GetType()));
}
@@ -244,10 +244,10 @@ public void IsIComponentManager()
[Fact]
public void IsIContext()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
foreach (var plugin in componentHub.PluginManager.Plugins)
{
Assert.True(typeof(IContext).IsAssignableFrom(plugin.GetType()), $"Plugin context {plugin.GetType().Name} does not implement IContext.");
diff --git a/src/WebExpress.WebCore.Test/Manager/UnitTestResourceManager.cs b/src/WebExpress.WebCore.Test/Manager/UnitTestResourceManager.cs
index 7a6728d..71fefd6 100644
--- a/src/WebExpress.WebCore.Test/Manager/UnitTestResourceManager.cs
+++ b/src/WebExpress.WebCore.Test/Manager/UnitTestResourceManager.cs
@@ -17,10 +17,10 @@ public class UnitTestResourceManager
[Fact]
public void Register()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.Equal(12, componentHub.ResourceManager.Resources.Count());
}
@@ -30,12 +30,12 @@ public void Register()
[Fact]
public void Remove()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var plugin = componentHub.PluginManager.GetPlugin(typeof(TestPlugin));
var resourceManager = componentHub.ResourceManager as ResourceManager;
- // test execution
+ // act
resourceManager.Remove(plugin);
Assert.Empty(componentHub.ResourceManager.Resources);
@@ -59,12 +59,12 @@ public void Remove()
[InlineData(typeof(TestApplicationC), typeof(TestResourceD), "webexpress.webcore.test.www.resources.testresourced")]
public void Id(Type applicationType, Type resourceType, string id)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType)?.FirstOrDefault();
var resource = componentHub.ResourceManager.GetResorces(resourceType, application)?.FirstOrDefault();
- // test execution
+ // act
Assert.Equal(id, resource?.EndpointId.ToString());
}
@@ -87,12 +87,12 @@ public void Id(Type applicationType, Type resourceType, string id)
public void RoutePath(Type applicationType, Type resourceType, string path)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType)?.FirstOrDefault();
var resource = componentHub.ResourceManager.GetResorces(resourceType, application)?.FirstOrDefault();
- // test execution
+ // act
Assert.Equal(path, resource.Route.ToString());
}
@@ -102,10 +102,10 @@ public void RoutePath(Type applicationType, Type resourceType, string path)
[Fact]
public void IsIComponentManager()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.True(typeof(IComponentManager).IsAssignableFrom(componentHub.ResourceManager.GetType()));
}
@@ -115,10 +115,10 @@ public void IsIComponentManager()
[Fact]
public void IsIContext()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
foreach (var resources in componentHub.ResourceManager.Resources)
{
Assert.True(typeof(IContext).IsAssignableFrom(resources.GetType()), $"Resource context {resources.GetType().Name} does not implement IContext.");
diff --git a/src/WebExpress.WebCore.Test/Manager/UnitTestRestApiManager.cs b/src/WebExpress.WebCore.Test/Manager/UnitTestRestApiManager.cs
index 9c18eba..c4fdff7 100644
--- a/src/WebExpress.WebCore.Test/Manager/UnitTestRestApiManager.cs
+++ b/src/WebExpress.WebCore.Test/Manager/UnitTestRestApiManager.cs
@@ -1,9 +1,10 @@
using WebExpress.WebCore.Test.Fixture;
-using WebExpress.WebCore.Test.WWW.Api._1;
+using WebExpress.WebCore.Test.WWW.Api._1_;
using WebExpress.WebCore.Test.WWW.Api._2;
-using WebExpress.WebCore.Test.WWW.Api._3;
+using WebExpress.WebCore.Test.WWW.Api.V3;
using WebExpress.WebCore.WebComponent;
using WebExpress.WebCore.WebMessage;
+using WebExpress.WebCore.WebParameter;
using WebExpress.WebCore.WebRestApi;
namespace WebExpress.WebCore.Test.Manager
@@ -20,10 +21,10 @@ public class UnitTestRestApiManager
[Fact]
public void Register()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.Equal(9, componentHub.RestApiManager.RestApis.Count());
}
@@ -33,12 +34,12 @@ public void Register()
[Fact]
public void Remove()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var plugin = componentHub.PluginManager.GetPlugin(typeof(TestPlugin));
var apiManager = componentHub.RestApiManager as RestApiManager;
- // test execution
+ // act
apiManager.Remove(plugin);
// validation
@@ -49,23 +50,23 @@ public void Remove()
/// Test the id property of the rest api.
///
[Theory]
- [InlineData(typeof(TestApplicationA), typeof(TestRestApiA), "webexpress.webcore.test.www.api._1.testrestapia")]
+ [InlineData(typeof(TestApplicationA), typeof(TestRestApiA), "webexpress.webcore.test.www.api._1_.testrestapia")]
[InlineData(typeof(TestApplicationA), typeof(TestRestApiB), "webexpress.webcore.test.www.api._2.testrestapib")]
- [InlineData(typeof(TestApplicationA), typeof(TestRestApiC), "webexpress.webcore.test.www.api._3.testrestapic")]
- [InlineData(typeof(TestApplicationB), typeof(TestRestApiA), "webexpress.webcore.test.www.api._1.testrestapia")]
+ [InlineData(typeof(TestApplicationA), typeof(TestRestApiC), "webexpress.webcore.test.www.api.v3.testrestapic")]
+ [InlineData(typeof(TestApplicationB), typeof(TestRestApiA), "webexpress.webcore.test.www.api._1_.testrestapia")]
[InlineData(typeof(TestApplicationB), typeof(TestRestApiB), "webexpress.webcore.test.www.api._2.testrestapib")]
- [InlineData(typeof(TestApplicationB), typeof(TestRestApiC), "webexpress.webcore.test.www.api._3.testrestapic")]
- [InlineData(typeof(TestApplicationC), typeof(TestRestApiA), "webexpress.webcore.test.www.api._1.testrestapia")]
+ [InlineData(typeof(TestApplicationB), typeof(TestRestApiC), "webexpress.webcore.test.www.api.v3.testrestapic")]
+ [InlineData(typeof(TestApplicationC), typeof(TestRestApiA), "webexpress.webcore.test.www.api._1_.testrestapia")]
[InlineData(typeof(TestApplicationC), typeof(TestRestApiB), "webexpress.webcore.test.www.api._2.testrestapib")]
- [InlineData(typeof(TestApplicationC), typeof(TestRestApiC), "webexpress.webcore.test.www.api._3.testrestapic")]
+ [InlineData(typeof(TestApplicationC), typeof(TestRestApiC), "webexpress.webcore.test.www.api.v3.testrestapic")]
public void Id(Type applicationType, Type resourceType, string id)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType)?.FirstOrDefault();
var api = componentHub.RestApiManager.GetRestApi(resourceType, application)?.FirstOrDefault();
- // test execution
+ // act
Assert.Equal(id, api?.EndpointId.ToString());
}
@@ -84,31 +85,61 @@ public void Id(Type applicationType, Type resourceType, string id)
[InlineData(typeof(TestApplicationC), typeof(TestRestApiC), "/server/api/3/testrestapic")]
public void RoutePath(Type applicationType, Type resourceType, string path)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType)?.FirstOrDefault();
var api = componentHub.RestApiManager.GetRestApi(resourceType, application)?.FirstOrDefault();
- // test execution
+ // act
Assert.Equal(path, api?.Route.ToString());
}
+ ///
+ /// Test the version from path property of the rest api.
+ ///
+ [Theory]
+ [InlineData(typeof(TestApplicationA), typeof(TestRestApiA), "1")]
+ [InlineData(typeof(TestApplicationA), typeof(TestRestApiB), "2")]
+ [InlineData(typeof(TestApplicationA), typeof(TestRestApiC), "3")]
+ [InlineData(typeof(TestApplicationB), typeof(TestRestApiA), "1")]
+ [InlineData(typeof(TestApplicationB), typeof(TestRestApiB), "2")]
+ [InlineData(typeof(TestApplicationB), typeof(TestRestApiC), "3")]
+ [InlineData(typeof(TestApplicationC), typeof(TestRestApiA), "1")]
+ [InlineData(typeof(TestApplicationC), typeof(TestRestApiB), "2")]
+ [InlineData(typeof(TestApplicationC), typeof(TestRestApiC), "3")]
+ public void Version(Type applicationType, Type resourceType, string expected)
+ {
+ // arrange
+ var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
+ var application = componentHub.ApplicationManager.GetApplications(applicationType)?.FirstOrDefault();
+ var api = componentHub.RestApiManager.GetRestApi(resourceType, application)?.FirstOrDefault();
+ componentHub.SitemapManager.Refresh();
+ var uri = componentHub.SitemapManager.GetUri(resourceType, application);
+
+ // act
+ var version = uri.Parameters
+ .Where(x => x.Key == "_apiversion")
+ .FirstOrDefault();
+
+ // act
+ Assert.Equal(expected, version.Value);
+ }
+
///
/// Test the context path property of the rest api.
///
[Theory]
- [InlineData(typeof(TestApplicationA), typeof(TestRestApiA), CrudMethod.POST)]
- [InlineData(typeof(TestApplicationA), typeof(TestRestApiA), CrudMethod.GET)]
- [InlineData(typeof(TestApplicationA), typeof(TestRestApiB), CrudMethod.GET)]
- [InlineData(typeof(TestApplicationA), typeof(TestRestApiC), CrudMethod.GET)]
- public void Method(Type applicationType, Type resourceType, CrudMethod method)
+ [InlineData(typeof(TestApplicationA), typeof(TestRestApiA), RequestMethod.POST)]
+ [InlineData(typeof(TestApplicationA), typeof(TestRestApiA), RequestMethod.GET)]
+ [InlineData(typeof(TestApplicationA), typeof(TestRestApiB), RequestMethod.GET)]
+ public void Method(Type applicationType, Type resourceType, RequestMethod method)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType)?.FirstOrDefault();
var api = componentHub.RestApiManager.GetRestApi(resourceType, application)?.FirstOrDefault();
- // test execution
+ // act
Assert.Contains(method, api?.Methods);
}
@@ -118,10 +149,10 @@ public void Method(Type applicationType, Type resourceType, CrudMethod method)
[Fact]
public void IsIComponentManager()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.True(typeof(IComponentManager).IsAssignableFrom(componentHub.RestApiManager.GetType()));
}
@@ -131,10 +162,10 @@ public void IsIComponentManager()
[Fact]
public void IsIContext()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
foreach (var api in componentHub.RestApiManager.RestApis)
{
Assert.True(typeof(IContext).IsAssignableFrom(api.GetType()), $"Api context {api.GetType().Name} does not implement IContext.");
@@ -150,11 +181,11 @@ public void IsIContext()
[InlineData(" ")]
public void ValidateRequire(string input)
{
- // preconditions
- var request = UnitTestFixture.CrerateRequestMock($"name={input}");
+ // arrange
+ var request = UnitTestFixture.CreateRequestMock($"name={input}");
request.AddParameter(new Parameter("name", input, ParameterScope.Parameter));
- // test execution
+ // act
var validator = new RestApiValidator(request)
.Require("name");
@@ -172,11 +203,11 @@ public void ValidateRequire(string input)
[InlineData("ab")]
public void ValidateMinLength(string input)
{
- // preconditions
- var request = UnitTestFixture.CrerateRequestMock();
+ // arrange
+ var request = UnitTestFixture.CreateRequestMock();
request.AddParameter(new Parameter("code", input, ParameterScope.Parameter));
- // test execution
+ // act
var validator = new RestApiValidator(request)
.MinLength("code", 3);
@@ -192,12 +223,12 @@ public void ValidateMinLength(string input)
[InlineData(300)]
public void ValidateMaxLength(int length)
{
- // preconditions
+ // arrange
var input = new string('x', length);
- var request = UnitTestFixture.CrerateRequestMock();
+ var request = UnitTestFixture.CreateRequestMock();
request.AddParameter(new Parameter("bio", input, ParameterScope.Parameter));
- // test execution
+ // act
var validator = new RestApiValidator(request)
.MaxLength("bio", 255);
@@ -215,11 +246,11 @@ public void ValidateMaxLength(int length)
[InlineData("@nouser.com")]
public void ValidateEmail(string email)
{
- // preconditions
- var request = UnitTestFixture.CrerateRequestMock();
+ // arrange
+ var request = UnitTestFixture.CreateRequestMock();
request.AddParameter(new Parameter("email", email, ParameterScope.Parameter));
- // test execution
+ // act
var validator = new RestApiValidator(request)
.Email("email");
@@ -237,11 +268,11 @@ public void ValidateEmail(string email)
[InlineData("123a")]
public void ValidateIsInt(string input)
{
- // preconditions
- var request = UnitTestFixture.CrerateRequestMock();
+ // arrange
+ var request = UnitTestFixture.CreateRequestMock();
request.AddParameter(new Parameter("age", input, ParameterScope.Parameter));
- // test execution
+ // act
var validator = new RestApiValidator(request)
.IsInt("age");
@@ -258,11 +289,11 @@ public void ValidateIsInt(string input)
[InlineData("WrongCase")]
public void ValidateEqualTo(string input)
{
- // preconditions
- var request = UnitTestFixture.CrerateRequestMock();
+ // arrange
+ var request = UnitTestFixture.CreateRequestMock();
request.AddParameter(new Parameter("role", input, ParameterScope.Parameter));
- // test execution
+ // act
var validator = new RestApiValidator(request)
.EqualTo("role", "admin");
@@ -279,7 +310,7 @@ public void ValidateEqualTo(string input)
[InlineData("101")]
public void ValidateRange(string input)
{
- var request = UnitTestFixture.CrerateRequestMock();
+ var request = UnitTestFixture.CreateRequestMock();
request.AddParameter(new Parameter("level", input, ParameterScope.Parameter));
var validator = new RestApiValidator(request)
@@ -297,7 +328,7 @@ public void ValidateRange(string input)
[InlineData("xyz-start")]
public void ValidateStartsWith(string input)
{
- var request = UnitTestFixture.CrerateRequestMock();
+ var request = UnitTestFixture.CreateRequestMock();
request.AddParameter(new Parameter("code", input, ParameterScope.Parameter));
var validator = new RestApiValidator(request)
@@ -315,7 +346,7 @@ public void ValidateStartsWith(string input)
[InlineData("document.pdf")]
public void ValidateEndsWith(string input)
{
- var request = UnitTestFixture.CrerateRequestMock();
+ var request = UnitTestFixture.CreateRequestMock();
request.AddParameter(new Parameter("filename", input, ParameterScope.Parameter));
var validator = new RestApiValidator(request)
@@ -333,7 +364,7 @@ public void ValidateEndsWith(string input)
[InlineData("anonymous")]
public void ValidateIn(string input)
{
- var request = UnitTestFixture.CrerateRequestMock();
+ var request = UnitTestFixture.CreateRequestMock();
request.AddParameter(new Parameter("role", input, ParameterScope.Parameter));
var validator = new RestApiValidator(request)
@@ -351,7 +382,7 @@ public void ValidateIn(string input)
[InlineData("foo bar")]
public void ValidateContains(string input)
{
- var request = UnitTestFixture.CrerateRequestMock();
+ var request = UnitTestFixture.CreateRequestMock();
request.AddParameter(new Parameter("description", input, ParameterScope.Parameter));
var validator = new RestApiValidator(request)
@@ -371,7 +402,7 @@ public enum Difficulty { Easy, Medium, Hard }
[InlineData("easy-peasy")]
public void ValidateMatchesEnum(string value)
{
- var request = UnitTestFixture.CrerateRequestMock();
+ var request = UnitTestFixture.CreateRequestMock();
request.AddParameter(new Parameter("difficulty", value, ParameterScope.Parameter));
var validator = new RestApiValidator(request)
@@ -389,7 +420,7 @@ public void ValidateMatchesEnum(string value)
[InlineData("31/31/2020")]
public void ValidateIsDate(string input)
{
- var request = UnitTestFixture.CrerateRequestMock();
+ var request = UnitTestFixture.CreateRequestMock();
request.AddParameter(new Parameter("date", input, ParameterScope.Parameter));
var validator = new RestApiValidator(request)
@@ -408,7 +439,7 @@ public void ValidateIsDate(string input)
[InlineData("nonpirate")]
public void ValidateCustom(string input)
{
- var request = UnitTestFixture.CrerateRequestMock();
+ var request = UnitTestFixture.CreateRequestMock();
request.AddParameter(new Parameter("nickname", input, ParameterScope.Parameter));
var validator = new RestApiValidator(request)
@@ -431,7 +462,7 @@ public void ValidateCustom(string input)
[InlineData("true", "")]
public void ValidateWhen_ConditionalRequire(string subscribe, string email)
{
- var request = UnitTestFixture.CrerateRequestMock();
+ var request = UnitTestFixture.CreateRequestMock();
request.AddParameter(new Parameter("subscribe", subscribe, ParameterScope.Parameter));
request.AddParameter(new Parameter("email", email, ParameterScope.Parameter));
@@ -451,7 +482,7 @@ public void ValidateWhen_ConditionalRequire(string subscribe, string email)
[InlineData(null, "")]
public void ValidateWhen_ConditionFalse(string subscribe, string email)
{
- var request = UnitTestFixture.CrerateRequestMock();
+ var request = UnitTestFixture.CreateRequestMock();
request.AddParameter(new Parameter("subscribe", subscribe, ParameterScope.Parameter));
request.AddParameter(new Parameter("email", email, ParameterScope.Parameter));
diff --git a/src/WebExpress.WebCore.Test/Manager/UnitTestSessionManager.cs b/src/WebExpress.WebCore.Test/Manager/UnitTestSessionManager.cs
index e7bf41e..afd01d4 100644
--- a/src/WebExpress.WebCore.Test/Manager/UnitTestSessionManager.cs
+++ b/src/WebExpress.WebCore.Test/Manager/UnitTestSessionManager.cs
@@ -1,6 +1,6 @@
using WebExpress.WebCore.Test.Fixture;
using WebExpress.WebCore.WebComponent;
-using WebExpress.WebCore.WebMessage;
+using WebExpress.WebCore.WebParameter;
using WebExpress.WebCore.WebSession.Model;
namespace WebExpress.WebCore.Test.Manager
@@ -17,10 +17,10 @@ public class UnitTestSessionManager
[Fact]
public void Register()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.NotNull(componentHub.SessionManager);
}
@@ -30,10 +30,10 @@ public void Register()
[Fact]
public void IsIComponentManager()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.True(typeof(IComponentManager).IsAssignableFrom(componentHub.SessionManager.GetType()));
}
@@ -43,11 +43,11 @@ public void IsIComponentManager()
[Fact]
public void GetSession()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- var request = UnitTestFixture.CrerateRequestMock();
+ var request = UnitTestFixture.CreateRequestMock();
- // test execution
+ // act
var session = componentHub.SessionManager.GetSession(request);
Assert.NotNull(session);
@@ -59,12 +59,12 @@ public void GetSession()
[Fact]
public void AddPropertyToSession()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- var request = UnitTestFixture.CrerateRequestMock();
+ var request = UnitTestFixture.CreateRequestMock();
var session = componentHub.SessionManager.GetSession(request);
- // test execution
+ // act
session.SetProperty(new SessionPropertyParameter(new Parameter("test", "test param", ParameterScope.Session)));
var testProperty = session.GetProperty();
@@ -81,12 +81,12 @@ public void AddPropertyToSession()
[Fact]
public void RemovePropertyFromSession()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- var request = UnitTestFixture.CrerateRequestMock();
+ var request = UnitTestFixture.CreateRequestMock();
var session = componentHub.SessionManager.GetSession(request);
- // test execution
+ // act
session.SetProperty(new SessionPropertyParameter(new Parameter("test", "test param", ParameterScope.Session)));
session.RemoveProperty();
diff --git a/src/WebExpress.WebCore.Test/Manager/UnitTestSettingPageManager.cs b/src/WebExpress.WebCore.Test/Manager/UnitTestSettingPageManager.cs
index bab64fb..098c40d 100644
--- a/src/WebExpress.WebCore.Test/Manager/UnitTestSettingPageManager.cs
+++ b/src/WebExpress.WebCore.Test/Manager/UnitTestSettingPageManager.cs
@@ -17,10 +17,10 @@ public class UnitTestSettingPageManager
[Fact]
public void RegisterSettingPages()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.Equal(9, componentHub.SettingPageManager.SettingPages.Count());
}
@@ -30,10 +30,10 @@ public void RegisterSettingPages()
[Fact]
public void RegisterSettingCategories()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.Equal(9, componentHub.SettingPageManager.SettingCategories.Count());
}
@@ -43,10 +43,10 @@ public void RegisterSettingCategories()
[Fact]
public void RegisterSettingGroups()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.Equal(9, componentHub.SettingPageManager.SettingGroups.Count());
}
@@ -56,12 +56,12 @@ public void RegisterSettingGroups()
[Fact]
public void Remove()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var plugin = componentHub.PluginManager.GetPlugin(typeof(TestPlugin));
var settingPageManager = componentHub.SettingPageManager as SettingPageManager;
- // test execution
+ // act
settingPageManager.Remove(plugin);
Assert.Empty(componentHub.SettingPageManager.SettingPages);
@@ -82,12 +82,12 @@ public void Remove()
[InlineData(typeof(TestApplicationC), typeof(TestSettingPageC), "webexpress.webcore.test.www.settings.testsettingpagec")]
public void Id(Type applicationType, Type resourceType, string id)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType)?.FirstOrDefault();
var settingPage = componentHub.SettingPageManager.GetSettingPages(resourceType, application)?.FirstOrDefault();
- // test execution
+ // act
Assert.Equal(id, settingPage.EndpointId.ToString());
}
@@ -103,12 +103,12 @@ public void Id(Type applicationType, Type resourceType, string id)
[InlineData(typeof(TestApplicationC), typeof(TestSettingPageB), "webindex:settingpageb.label")]
public void Title(Type applicationType, Type resourceType, string title)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType)?.FirstOrDefault();
var settingPage = componentHub.SettingPageManager.GetSettingPages(resourceType, application)?.FirstOrDefault();
- // test execution
+ // act
Assert.Equal(title, settingPage.PageTitle);
}
@@ -127,12 +127,12 @@ public void Title(Type applicationType, Type resourceType, string title)
[InlineData(typeof(TestApplicationC), typeof(TestSettingPageC), "/server/settings/testsettingpagec")]
public void RoutePath(Type applicationType, Type resourceType, string path)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType)?.FirstOrDefault();
var settingPage = componentHub.SettingPageManager.GetSettingPages(resourceType, application)?.FirstOrDefault();
- // test execution
+ // act
Assert.Equal(path, settingPage.Route.ToString());
}
@@ -142,10 +142,10 @@ public void RoutePath(Type applicationType, Type resourceType, string path)
[Fact]
public void IsIComponentManager()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.True(typeof(IComponentManager).IsAssignableFrom(componentHub.SettingPageManager.GetType()));
}
@@ -155,10 +155,10 @@ public void IsIComponentManager()
[Fact]
public void IsIContext()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
foreach (var settingPages in componentHub.SettingPageManager.SettingPages)
{
Assert.True(typeof(IContext).IsAssignableFrom(settingPages.GetType()), $"Page context {settingPages.GetType().Name} does not implement IContext.");
@@ -174,12 +174,12 @@ public void IsIContext()
[InlineData(typeof(TestApplicationC), new[] { "SettingCategory A", "SettingCategory B", "SettingCategory C" })]
public void CategoryName(Type applicationType, params string[] names)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType)?.FirstOrDefault();
var settingCategories = componentHub.SettingPageManager.GetSettingCategories(application);
- // test execution
+ // act
Assert.Equal([.. names], [.. settingCategories.Select(x => x.Name)]);
}
@@ -192,12 +192,12 @@ public void CategoryName(Type applicationType, params string[] names)
[InlineData(typeof(TestApplicationC), new[] { "WebExpress.WebCore.Test.TestIconBell", "WebExpress.WebCore.Test.TestIconProfile", null })]
public void CategoryIcon(Type applicationType, params string[] icons)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType)?.FirstOrDefault();
var settingCategories = componentHub.SettingPageManager.GetSettingCategories(application);
- // test execution
+ // act
Assert.Equal([.. icons], [.. settingCategories.Select(x => x.Icon?.ToString())]);
}
@@ -210,12 +210,12 @@ public void CategoryIcon(Type applicationType, params string[] icons)
[InlineData(typeof(TestApplicationC), new[] { "Description of category a.", "Description of category b.", "Description of category c." })]
public void CategoryDescription(Type applicationType, params string[] descriptions)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType)?.FirstOrDefault();
var settingCategories = componentHub.SettingPageManager.GetSettingCategories(application);
- // test execution
+ // act
Assert.Equal([.. descriptions], [.. settingCategories.Select(x => x.Description)]);
}
@@ -228,12 +228,12 @@ public void CategoryDescription(Type applicationType, params string[] descriptio
[InlineData(typeof(TestApplicationC), new[] { SettingSection.Preferences, SettingSection.Primary, SettingSection.Secondary })]
public void CategorySection(Type applicationType, params SettingSection[] sections)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType)?.FirstOrDefault();
var settingCategories = componentHub.SettingPageManager.GetSettingCategories(application);
- // test execution
+ // act
Assert.Equal([.. sections], [.. settingCategories.Select(x => x.Section)]);
}
@@ -248,13 +248,13 @@ public void CategorySection(Type applicationType, params SettingSection[] sectio
[InlineData(typeof(TestApplicationA), null, new[] { "SettingGroup C" })]
public void GroupName(Type applicationType, Type settingCategoryType, params string[] names)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType)?.FirstOrDefault();
var settingCategory = componentHub.SettingPageManager.GetSettingCategories(application).FirstOrDefault(x => x.CategoryId.ToString() == settingCategoryType?.FullName.ToLower());
var settinGroups = componentHub.SettingPageManager.GetSettingGroups(application, settingCategory);
- // test execution
+ // act
Assert.Equal([.. names], [.. settinGroups.Select(x => x.Name)]);
}
@@ -269,13 +269,13 @@ public void GroupName(Type applicationType, Type settingCategoryType, params str
[InlineData(typeof(TestApplicationA), null, new[] { "Description of group c." })]
public void GroupDescription(Type applicationType, Type settingCategoryType, params string[] descriptions)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType)?.FirstOrDefault();
var settingCategory = componentHub.SettingPageManager.GetSettingCategories(application).FirstOrDefault(x => x.CategoryId.ToString() == settingCategoryType?.FullName.ToLower());
var settinGroups = componentHub.SettingPageManager.GetSettingGroups(application, settingCategory);
- // test execution
+ // act
Assert.Equal([.. descriptions], [.. settinGroups.Select(x => x.Description)]);
}
@@ -290,13 +290,13 @@ public void GroupDescription(Type applicationType, Type settingCategoryType, par
[InlineData(typeof(TestApplicationA), null, new[] { SettingSection.Secondary })]
public void GroupSection(Type applicationType, Type settingCategoryType, params SettingSection[] sections)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType)?.FirstOrDefault();
var settingCategory = componentHub.SettingPageManager.GetSettingCategories(application).FirstOrDefault(x => x.CategoryId.ToString() == settingCategoryType?.FullName.ToLower());
var settinGroups = componentHub.SettingPageManager.GetSettingGroups(application, settingCategory);
- // test execution
+ // act
Assert.Equal([.. sections], [.. settinGroups.Select(x => x.Section)]);
}
@@ -311,13 +311,13 @@ public void GroupSection(Type applicationType, Type settingCategoryType, params
[InlineData(typeof(TestApplicationA), null)]
public void GroupCategory(Type applicationType, Type settingCategoryType)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType)?.FirstOrDefault();
var settingCategory = componentHub.SettingPageManager.GetSettingCategories(application).FirstOrDefault(x => x.CategoryId.ToString() == settingCategoryType?.FullName.ToLower());
var settinGroups = componentHub.SettingPageManager.GetSettingGroups(application, settingCategory);
- // test execution
+ // act
Assert.Equal(settinGroups.Count(), settinGroups.Where(x => x.SettingCategory == settingCategory).Count());
}
@@ -332,14 +332,16 @@ public void GroupCategory(Type applicationType, Type settingCategoryType)
[InlineData(typeof(TestApplicationA), null, typeof(TestSettingPageC))]
public void GetFirstSettingPage(Type applicationType, Type settingCategoryType, Type firstPageType)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType)?.FirstOrDefault();
var settingCategory = componentHub.SettingPageManager.GetSettingCategories(application).FirstOrDefault(x => x.CategoryId.ToString() == settingCategoryType?.FullName.ToLower());
- var firstPage = firstPageType != null ? componentHub.SettingPageManager.GetSettingPages(firstPageType, application).FirstOrDefault() : null;
+ var firstPage = firstPageType is not null
+ ? componentHub.SettingPageManager.GetSettingPages(firstPageType, application).FirstOrDefault()
+ : null;
var settingPage = componentHub.SettingPageManager.GetFirstSettingPage(application, settingCategory);
- // test execution
+ // act
Assert.Equal(firstPage, settingPage);
}
}
diff --git a/src/WebExpress.WebCore.Test/Manager/UnitTestSitemapManager.cs b/src/WebExpress.WebCore.Test/Manager/UnitTestSitemapManager.cs
index 3ec7ab8..76c0eb5 100644
--- a/src/WebExpress.WebCore.Test/Manager/UnitTestSitemapManager.cs
+++ b/src/WebExpress.WebCore.Test/Manager/UnitTestSitemapManager.cs
@@ -1,7 +1,7 @@
using WebExpress.WebCore.Test.Fixture;
-using WebExpress.WebCore.Test.WWW.Api._1;
+using WebExpress.WebCore.Test.WWW.Api._1_;
using WebExpress.WebCore.Test.WWW.Api._2;
-using WebExpress.WebCore.Test.WWW.Api._3;
+using WebExpress.WebCore.Test.WWW.Api.V3;
using WebExpress.WebCore.Test.WWW.Resources;
using WebExpress.WebCore.WebComponent;
using WebExpress.WebCore.WebSitemap;
@@ -18,16 +18,18 @@ public class UnitTestSitemapManager
///
/// Test the refresh function of the sitemap manager.
///
- [Fact]
- public void Refresh()
+ [Theory]
+ [InlineData(106)]
+ public void Refresh(int expected)
{
- // preconditions
+ // arrange
var componentManager = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
componentManager.SitemapManager.Refresh();
- Assert.Equal(97, componentManager.SitemapManager.SiteMap.Count());
+ // validation
+ Assert.Equal(expected, componentManager.SitemapManager.SiteMap.Count());
}
///
@@ -55,22 +57,22 @@ public void Refresh()
[InlineData("http://localhost:8080/server", "webexpress.webcore.test.www.index")]
[InlineData("http://localhost:8080/server/about", "webexpress.webcore.test.www.about")]
[InlineData("http://localhost:8080/server/contact", "webexpress.webcore.test.www.contact")]
- [InlineData("http://localhost:8080/server/appa/api/1/testrestapia", "webexpress.webcore.test.www.api._1.testrestapia")]
+ [InlineData("http://localhost:8080/server/appa/api/1/testrestapia", "webexpress.webcore.test.www.api._1_.testrestapia")]
[InlineData("http://localhost:8080/server/appa/api/2/testrestapib", "webexpress.webcore.test.www.api._2.testrestapib")]
- [InlineData("http://localhost:8080/server/appa/api/3/testrestapic", "webexpress.webcore.test.www.api._3.testrestapic")]
+ [InlineData("http://localhost:8080/server/appa/api/3/testrestapic", "webexpress.webcore.test.www.api.v3.testrestapic")]
[InlineData("http://localhost:8080/server/appa/assets/css/mycss.css", "webexpress.webcore.test.css.mycss.css")]
[InlineData("http://localhost:8080/server/appa/assets/js/myjavascript.js", "webexpress.webcore.test.js.myjavascript.js")]
[InlineData("http://localhost:8080/server/appa/assets/js/myjavascript.mini.js", "webexpress.webcore.test.js.myjavascript.mini.js")]
[InlineData("http://localhost:8080/uri/does/not/exist", null)]
public void SearchResource(string uri, string id)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var context = UnitTestFixture.CreateHttpContextMock();
var httpServerContext = UnitTestFixture.CreateHttpServerContextMock();
componentHub.SitemapManager.Refresh();
- // test execution
+ // act
var searchResult = componentHub.SitemapManager.SearchResource(new System.Uri(uri), new SearchContext()
{
HttpServerContext = httpServerContext,
@@ -78,8 +80,9 @@ public void SearchResource(string uri, string id)
HttpContext = context
});
- componentHub.EndpointManager.HandleRequest(UnitTestFixture.CrerateRequestMock(), searchResult?.EndpointContext);
+ componentHub.EndpointManager.HandleRequest(UnitTestFixture.CreateRequestMock(), searchResult?.EndpointContext);
+ // validation
Assert.Equal(id, searchResult?.EndpointContext?.EndpointId.ToString());
}
@@ -110,14 +113,25 @@ public void SearchResource(string uri, string id)
[InlineData(typeof(TestApplicationA), typeof(WWW.Products.Details.Index), 2, "/server/appa/products/2")]
public void GetUri(Type applicationType, Type resourceType, int? param, string expected)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType)?.FirstOrDefault();
componentHub.SitemapManager.Refresh();
+ var parameter = param.HasValue
+ ? new TestParameterA(param ?? 0)
+ : new TestParameterA();
- // test execution
- var uri = componentHub.SitemapManager.GetUri(resourceType, application, [param.HasValue ? new TestParameterA(param.Value) : null]);
+ // act
+ var uri = componentHub.SitemapManager.GetUri
+ (
+ resourceType,
+ application,
+ [
+ parameter
+ ]
+ );
+ // validation
Assert.Equal(expected, uri?.ToString());
}
@@ -133,9 +147,9 @@ public void GetUri(Type applicationType, Type resourceType, int? param, string e
[InlineData("http://localhost:8080/server/appa/assets/css/mycss.css", "webexpress.webcore.test.css.mycss.css")]
[InlineData("http://localhost:8080/server/appa/assets/js/myjavascript.js", "webexpress.webcore.test.js.myjavascript.js")]
[InlineData("http://localhost:8080/server/appa/assets/js/myjavascript.mini.js", "webexpress.webcore.test.js.myjavascript.mini.js")]
- [InlineData("http://localhost:8080/server/appa/api/1/testrestapia", "webexpress.webcore.test.www.api._1.testrestapia")]
+ [InlineData("http://localhost:8080/server/appa/api/1/testrestapia", "webexpress.webcore.test.www.api._1_.testrestapia")]
[InlineData("http://localhost:8080/server/appa/api/2/TestRestApiB", "webexpress.webcore.test.www.api._2.testrestapib")]
- [InlineData("http://localhost:8080/server/appa/api/3/testrestapic", "webexpress.webcore.test.www.api._3.testrestapic")]
+ [InlineData("http://localhost:8080/server/appa/api/3/testrestapic", "webexpress.webcore.test.www.api.v3.testrestapic")]
[InlineData("http://localhost:8080/server/appa", "webexpress.webcore.test.www.index")]
[InlineData("http://localhost:8080/server/appa/", "webexpress.webcore.test.www.index")]
[InlineData("http://localhost:8080/server/appa/about", "webexpress.webcore.test.www.about")]
@@ -156,14 +170,15 @@ public void GetUri(Type applicationType, Type resourceType, int? param, string e
[InlineData("http://localhost:8080/server/appa/products/10E96737-5C72-4C25-9E74-F96D8863D123/", "webexpress.webcore.test.www.products.details.index")]
public void GetEndpoint(string uri, string expected)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
componentHub.SitemapManager.Refresh();
- // test execution
+ // act
var endpoint = componentHub.SitemapManager.GetEndpoint(new UriEndpoint(uri));
- Assert.Equal(expected, endpoint?.EndpointId?.ToString());
+ // validation
+ AssertExtensions.EqualWithPlaceholders(expected, endpoint?.EndpointId?.ToString());
}
///
@@ -172,10 +187,10 @@ public void GetEndpoint(string uri, string expected)
[Fact]
public void IsIComponentManager()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.True(typeof(IComponentManager).IsAssignableFrom(componentHub.SitemapManager.GetType()));
}
}
diff --git a/src/WebExpress.WebCore.Test/Manager/UnitTestSocketManager.cs b/src/WebExpress.WebCore.Test/Manager/UnitTestSocketManager.cs
new file mode 100644
index 0000000..e3cba42
--- /dev/null
+++ b/src/WebExpress.WebCore.Test/Manager/UnitTestSocketManager.cs
@@ -0,0 +1,119 @@
+using WebExpress.WebCore.Test.Fixture;
+using WebExpress.WebCore.WebComponent;
+using WebExpress.WebCore.WebPlugin;
+using WebExpress.WebCore.WebSocket;
+
+namespace WebExpress.WebCore.Test.Manager
+{
+ ///
+ /// Test the websocket manager.
+ ///
+ [Collection("NonParallelTests")]
+ public class UnitTestSocketManager
+ {
+ ///
+ /// Test the register function of the socket manager.
+ ///
+ [Fact]
+ public void Register()
+ {
+ // arrange
+ var componentHub = UnitTestFixture.CreateComponentHubMock();
+ var pluginManager = componentHub.PluginManager as PluginManager;
+ var socketManager = componentHub.SocketManager as SocketManager;
+
+ // act
+ pluginManager.Register();
+
+ // validation
+ Assert.Equal(3, socketManager.Sockets.Count());
+ Assert.Equal("webexpress.webcore.test.testsocketa", socketManager.GetSockets()?.FirstOrDefault()?.EndpointId?.ToString());
+ Assert.Equal("webexpress.webcore.test.testsocketa", socketManager.GetSockets(typeof(TestSocketA))?.FirstOrDefault()?.EndpointId?.ToString());
+ }
+
+ ///
+ /// Test the remove function of the socket manager.
+ ///
+ [Fact]
+ public void Remove()
+ {
+ // arrange
+ var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
+ var socketManager = componentHub.SocketManager as SocketManager;
+ var plugin = componentHub.PluginManager.GetPlugin(typeof(TestPlugin));
+
+ // act
+ socketManager.Remove(plugin);
+
+ // validation
+ Assert.Empty(socketManager.Sockets);
+ }
+
+ ///
+ /// Test the id property of the socket.
+ ///
+ [Theory]
+ [InlineData(typeof(TestApplicationA), "webexpress.webcore.test.testsocketa")]
+ [InlineData(typeof(TestApplicationB), "webexpress.webcore.test.testsocketa")]
+ [InlineData(typeof(TestApplicationC), "webexpress.webcore.test.testsocketa")]
+ public void Id(Type applicationType, string id)
+ {
+ // arrange
+ var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
+ var applicationContext = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
+ var socket = componentHub.SocketManager.GetSockets(applicationContext)
+ .FirstOrDefault();
+
+ // act
+ Assert.Equal(id, socket.EndpointId?.ToString());
+ }
+
+ ///
+ /// Test the context path property of the socket.
+ ///
+ [Theory]
+ [InlineData(typeof(TestApplicationA), "/server/appa/testsocketa")]
+ [InlineData(typeof(TestApplicationB), "/server/appb/testsocketa")]
+ [InlineData(typeof(TestApplicationC), "/server/testsocketa")]
+ public void ContextPath(Type applicationType, string contextPath)
+ {
+ // arrange
+ var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
+ var applicationContext = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
+ var socket = componentHub.SocketManager.GetSockets(applicationContext)
+ .FirstOrDefault();
+
+ // act
+ Assert.Equal(contextPath, socket.Route.ToString());
+ }
+
+ ///
+ /// Tests whether the socket manager implements interface IComponentManager.
+ ///
+ [Fact]
+ public void IsIComponentManager()
+ {
+ // arrange
+ var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
+
+ // act
+ Assert.True(typeof(IComponentManager).IsAssignableFrom(componentHub.SocketManager.GetType()));
+ }
+
+ ///
+ /// Tests whether the application context implements interface IContext.
+ ///
+ [Fact]
+ public void IsIContext()
+ {
+ // arrange
+ var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
+
+ // act
+ foreach (var application in componentHub.SocketManager.Sockets)
+ {
+ Assert.True(typeof(IContext).IsAssignableFrom(application.GetType()), $"Socket context {application.GetType().Name} does not implement IContext.");
+ }
+ }
+ }
+}
diff --git a/src/WebExpress.WebCore.Test/Manager/UnitTestStatusPageManager.cs b/src/WebExpress.WebCore.Test/Manager/UnitTestStatusPageManager.cs
index 56ded64..cfcba08 100644
--- a/src/WebExpress.WebCore.Test/Manager/UnitTestStatusPageManager.cs
+++ b/src/WebExpress.WebCore.Test/Manager/UnitTestStatusPageManager.cs
@@ -16,10 +16,10 @@ public class UnitTestStatusPageManager
[Fact]
public void Register()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.Equal(12, componentHub.StatusPageManager.StatusPages.Count());
}
@@ -29,12 +29,12 @@ public void Register()
[Fact]
public void Remove()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var plugin = componentHub.PluginManager.GetPlugin(typeof(TestPlugin));
var statusPageManager = componentHub.StatusPageManager as StatusPageManager;
- // test execution
+ // act
statusPageManager.Remove(plugin);
Assert.Empty(componentHub.StatusPageManager.StatusPages);
@@ -51,12 +51,12 @@ public void Remove()
public void Id(Type applicationType, Type statusPageType, string id)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
var statusPage = componentHub.StatusPageManager.GetStatusPage(application, statusPageType);
- // test execution
+ // act
Assert.Equal(id, statusPage.StatusPageId.ToString());
}
@@ -78,12 +78,12 @@ public void Id(Type applicationType, Type statusPageType, string id)
[InlineData(typeof(TestApplicationC), typeof(TestStatusPage500), "webindex:homepage.label")]
public void Title(Type applicationType, Type resourceType, string title)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
var statusPage = componentHub.StatusPageManager.GetStatusPage(application, resourceType);
- // test execution
+ // act
Assert.Equal(title, statusPage.StatusTitle);
}
@@ -105,12 +105,12 @@ public void Title(Type applicationType, Type resourceType, string title)
[InlineData(typeof(TestApplicationC), typeof(TestStatusPage500), 500)]
public void Code(Type applicationType, Type statusPageType, int? code)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
var statusPage = componentHub.StatusPageManager.GetStatusPage(application, statusPageType);
- // test execution
+ // act
Assert.Equal(code, statusPage?.StatusCode);
}
@@ -132,12 +132,12 @@ public void Code(Type applicationType, Type statusPageType, int? code)
[InlineData(typeof(TestApplicationC), typeof(TestStatusPage500), "/server/webexpress/icon.png")]
public void Icon(Type applicationType, Type statusPageType, string icon)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
var statusPage = componentHub.StatusPageManager.GetStatusPage(application, statusPageType);
- // test execution
+ // act
Assert.Equal(icon, statusPage?.StatusIcon?.ToString());
}
@@ -152,12 +152,12 @@ public void Icon(Type applicationType, Type statusPageType, string icon)
[InlineData(typeof(TestApplicationA), 500, 500)]
public void CreateAndCheckCode(Type applicationType, int statusCode, int? expected)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
var statusResponse = componentHub.StatusPageManager.CreateStatusResponse("content", statusCode, application, UnitTestFixture.CreateHttpContextMock().Request);
- // test execution
+ // act
Assert.Equal(expected, statusResponse?.Status);
}
@@ -165,18 +165,22 @@ public void CreateAndCheckCode(Type applicationType, int statusCode, int? expect
/// Test the CreateStatusResponse function of the status page.
///
[Theory]
- [InlineData(typeof(TestApplicationA), 400, "content", "content", 78)]
- [InlineData(typeof(TestApplicationA), 500, "content", "content", 78)]
+ [InlineData(typeof(TestApplicationA), 400, "content", "content", 72)]
+ [InlineData(typeof(TestApplicationA), 500, "content", "content", 72)]
public void CreateAndCheckMessage(Type applicationType, int statusCode, string content, string expected, int length)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
+
+ // act
var statusResponse = componentHub.StatusPageManager.CreateStatusResponse(content, statusCode, application, UnitTestFixture.CreateHttpContextMock().Request);
- // test execution
+ // validation
+ var normalized = statusResponse?.Content?.ToString().Replace("\r\n", "\n").Replace("\r", "\n");
Assert.Contains(expected, statusResponse?.Content?.ToString());
- Assert.Equal(length, statusResponse?.Header?.ContentLength);
+ Assert.Equal(length, normalized.Length);
+ Assert.Equal(statusResponse?.Content?.ToString().Length, statusResponse?.Header?.ContentLength);
}
///
@@ -185,10 +189,10 @@ public void CreateAndCheckMessage(Type applicationType, int statusCode, string c
[Fact]
public void IsIComponentManager()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.True(typeof(IComponentManager).IsAssignableFrom(componentHub.StatusPageManager.GetType()));
}
@@ -198,10 +202,10 @@ public void IsIComponentManager()
[Fact]
public void IsIContext()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
foreach (var application in componentHub.StatusPageManager.StatusPages)
{
Assert.True(typeof(IContext).IsAssignableFrom(application.GetType()), $"Page context {application.GetType().Name} does not implement IContext.");
diff --git a/src/WebExpress.WebCore.Test/Manager/UnitTestTaskManager.cs b/src/WebExpress.WebCore.Test/Manager/UnitTestTaskManager.cs
index cc5b0db..c15ed63 100644
--- a/src/WebExpress.WebCore.Test/Manager/UnitTestTaskManager.cs
+++ b/src/WebExpress.WebCore.Test/Manager/UnitTestTaskManager.cs
@@ -15,10 +15,10 @@ public class UnitTestTaskManager
[Fact]
public void IsIComponentManager()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.True(typeof(IComponentManager).IsAssignableFrom(componentHub.ResourceManager.GetType()));
}
@@ -28,12 +28,12 @@ public void IsIComponentManager()
[Fact]
public void IsCompopnent()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
componentHub.TaskManager.CreateTask("test");
- // test execution
+ // act
foreach (var task in componentHub.TaskManager.Tasks)
{
Assert.True(typeof(IComponent).IsAssignableFrom(task.GetType()), $"Task {task.GetType().Name} does not implement IComponent.");
@@ -46,10 +46,10 @@ public void IsCompopnent()
[Fact]
public void CreateSystemTask()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
var task = componentHub.TaskManager.CreateTask("test");
Assert.Equal("test", task?.Id);
}
@@ -60,10 +60,10 @@ public void CreateSystemTask()
[Fact]
public void CreateOwnTask()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
var task = componentHub.TaskManager.CreateTask("test", null, []);
Assert.Equal("test", task?.Id);
}
@@ -74,11 +74,11 @@ public void CreateOwnTask()
[Fact]
public void ContainsTask()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var task = componentHub.TaskManager.CreateTask("test");
- // test execution
+ // act
var res = componentHub.TaskManager.ContainsTask("test");
Assert.True(res);
}
@@ -89,11 +89,11 @@ public void ContainsTask()
[Fact]
public void GetTask()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var task = componentHub.TaskManager.CreateTask("test");
- // test execution
+ // act
var res = componentHub.TaskManager.GetTask("test");
Assert.Equal(task, res);
}
@@ -104,11 +104,11 @@ public void GetTask()
[Fact]
public void RemoveTask()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var task = componentHub.TaskManager.CreateTask("test");
- // test execution
+ // act
componentHub.TaskManager.RemoveTask(task);
Assert.Empty(componentHub.TaskManager.Tasks);
}
diff --git a/src/WebExpress.WebCore.Test/Manager/UnitTestThemeManager.cs b/src/WebExpress.WebCore.Test/Manager/UnitTestThemeManager.cs
index d7300d8..dfc14a6 100644
--- a/src/WebExpress.WebCore.Test/Manager/UnitTestThemeManager.cs
+++ b/src/WebExpress.WebCore.Test/Manager/UnitTestThemeManager.cs
@@ -16,10 +16,10 @@ public class UnitTestThemeManager
[Fact]
public void Register()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.Equal(6, componentHub.ThemeManager.Themes.Count());
}
@@ -29,14 +29,15 @@ public void Register()
[Fact]
public void Remove()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var themeManager = componentHub.ThemeManager as ThemeManager;
var plugin = componentHub.PluginManager.GetPlugin(typeof(TestPlugin));
- // test execution
+ // act
themeManager.Remove(plugin);
+ // validation
Assert.Empty(componentHub.ThemeManager.Themes);
}
@@ -46,10 +47,10 @@ public void Remove()
[Fact]
public void IsIComponentManager()
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
- // test execution
+ // act
Assert.True(typeof(IComponentManager).IsAssignableFrom(componentHub.ThemeManager.GetType()));
}
@@ -65,14 +66,15 @@ public void IsIComponentManager()
[InlineData(typeof(TestApplicationC), typeof(TestThemeB), "webexpress.webcore.test.testthemeb")]
public void Id(Type applicationType, Type themeType, string id)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
- // test execution
+ // act
var themes = componentHub.ThemeManager.GetThemes(application, themeType);
- if (id == null)
+ // validation
+ if (id is null)
{
Assert.Empty(themes);
return;
@@ -93,14 +95,15 @@ public void Id(Type applicationType, Type themeType, string id)
[InlineData(typeof(TestApplicationC), typeof(TestThemeB), "TestThemeB")]
public void Name(Type applicationType, Type themeType, string name)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
- // test execution
+ // act
var themes = componentHub.ThemeManager.GetThemes(application, themeType);
- if (name == null)
+ // validation
+ if (name is null)
{
Assert.Empty(themes);
return;
@@ -121,13 +124,14 @@ public void Name(Type applicationType, Type themeType, string name)
[InlineData(typeof(TestApplicationC), typeof(TestThemeB), null)]
public void Description(Type applicationType, Type themeType, string expected)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
- // test execution
+ // act
var theme = componentHub.ThemeManager.GetThemes(application, themeType).FirstOrDefault();
+ // validation
Assert.NotNull(theme);
Assert.Equal(expected, theme?.Description);
}
@@ -144,13 +148,14 @@ public void Description(Type applicationType, Type themeType, string expected)
[InlineData(typeof(TestApplicationC), typeof(TestThemeB), null)]
public void Image(Type applicationType, Type themeType, string expected)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
- // test execution
+ // act
var theme = componentHub.ThemeManager.GetThemes(application, themeType).FirstOrDefault();
+ // validation
Assert.NotNull(theme);
Assert.Equal(expected, theme?.Image?.ToString());
}
@@ -167,13 +172,14 @@ public void Image(Type applicationType, Type themeType, string expected)
[InlineData(typeof(TestApplicationC), typeof(TestThemeB), ThemeMode.Light)]
public void Mode(Type applicationType, Type themeType, ThemeMode expected)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
- // test execution
+ // act
var theme = componentHub.ThemeManager.GetThemes(application, themeType).FirstOrDefault();
+ // validation
Assert.NotNull(theme);
Assert.Equal(expected, theme?.ThemeMode);
}
@@ -190,13 +196,14 @@ public void Mode(Type applicationType, Type themeType, ThemeMode expected)
[InlineData(typeof(TestApplicationC), typeof(TestThemeB), null)]
public void ThemeStyle(Type applicationType, Type themeType, string expected)
{
- // preconditions
+ // arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
- // test execution
+ // act
var theme = componentHub.ThemeManager.GetThemes(application, themeType).FirstOrDefault();
+ // validation
Assert.NotNull(theme);
Assert.Equal(expected, theme?.ThemeStyle?.ToString());
}
diff --git a/src/WebExpress.WebCore.Test/Message/UnitTestGetRequest.cs b/src/WebExpress.WebCore.Test/Message/UnitTestGetRequest.cs
index a7d6814..141d555 100644
--- a/src/WebExpress.WebCore.Test/Message/UnitTestGetRequest.cs
+++ b/src/WebExpress.WebCore.Test/Message/UnitTestGetRequest.cs
@@ -15,7 +15,7 @@ public class UnitTestGetRequest
public void General()
{
var content = UnitTestFixture.GetEmbeddedResource("general.get");
- var request = UnitTestFixture.CrerateRequestMock(content);
+ var request = UnitTestFixture.CreateRequestMock(content);
Assert.Equal("http://localhost:8080/abc/xyz/A7BCCCA9-4C7E-4117-9EE2-ECC3381B605A", request.Uri?.ToString());
}
@@ -27,7 +27,7 @@ public void General()
public void Less()
{
var content = UnitTestFixture.GetEmbeddedResource("less.get");
- var request = UnitTestFixture.CrerateRequestMock(content);
+ var request = UnitTestFixture.CreateRequestMock(content);
Assert.Equal("http://localhost:8080/abc/xyz/A7BCCCA9-4C7E-4117-9EE2-ECC3381B605A", request.Uri?.ToString());
}
@@ -39,7 +39,7 @@ public void Less()
public void Massive()
{
var content = UnitTestFixture.GetEmbeddedResource("massive.get");
- var request = UnitTestFixture.CrerateRequestMock(content);
+ var request = UnitTestFixture.CreateRequestMock(content);
Assert.Equal("http://localhost:8080/abc/xyz/A7BCCCA9-4C7E-4117-9EE2-ECC3381B605A", request.Uri?.ToString());
}
@@ -51,7 +51,7 @@ public void Massive()
public void GetParameter()
{
var content = UnitTestFixture.GetEmbeddedResource("param.get");
- var request = UnitTestFixture.CrerateRequestMock(content);
+ var request = UnitTestFixture.CreateRequestMock(content);
var param = request?.GetParameter("a")?.Value;
Assert.Equal("http://localhost:8080/abc/xyz/A7BCCCA9-4C7E-4117-9EE2-ECC3381B605A", request.Uri?.ToString());
@@ -65,7 +65,7 @@ public void GetParameter()
public void GetParameterWithUmlaut()
{
var content = UnitTestFixture.GetEmbeddedResource("param_umlaut.get");
- var request = UnitTestFixture.CrerateRequestMock(content);
+ var request = UnitTestFixture.CreateRequestMock(content);
var a = request?.GetParameter("a")?.Value;
var b = request?.GetParameter("b")?.Value;
diff --git a/src/WebExpress.WebCore.Test/Message/UnitTestPostRequest.cs b/src/WebExpress.WebCore.Test/Message/UnitTestPostRequest.cs
index 8b73d5c..856cdf1 100644
--- a/src/WebExpress.WebCore.Test/Message/UnitTestPostRequest.cs
+++ b/src/WebExpress.WebCore.Test/Message/UnitTestPostRequest.cs
@@ -11,7 +11,7 @@ public class UnitTestPostRequest : UnitTestRequest
// Assert.True
// (
- // param != null && param == "1"
+ // param is not null && param == "1"
// );
//}
@@ -26,9 +26,9 @@ public class UnitTestPostRequest : UnitTestRequest
// Assert.True
// (
- // a != null && a == "ä" &&
- // b != null && b == "ö ü" &&
- // s != null && s == "1"
+ // a is not null && a == "ä" &&
+ // b is not null && b == "ö ü" &&
+ // s is not null && s == "1"
// );
//}
diff --git a/src/WebExpress.WebCore.Test/Route/UnitTestRoute.cs b/src/WebExpress.WebCore.Test/Route/UnitTestRoute.cs
index 862f497..9d8760b 100644
--- a/src/WebExpress.WebCore.Test/Route/UnitTestRoute.cs
+++ b/src/WebExpress.WebCore.Test/Route/UnitTestRoute.cs
@@ -19,12 +19,13 @@ public class UnitTestRoute
[InlineData("/a/b/c", "/d/e/f", "/a/b/c/d/e/f", 7)]
public void ConcatString(string baseRoute, string segment, string expected, int count)
{
- // preconditions
+ // arrange
var route = new RouteEndpoint(baseRoute);
- // test execution
+ // act
var concat = route.Concat(segment);
+ // validation
Assert.Equal(expected, concat.ToString());
Assert.Equal(count, concat.PathSegments.Count());
}
@@ -39,12 +40,15 @@ public void ConcatString(string baseRoute, string segment, string expected, int
[InlineData("/a/b/c", "/d/e/f", "/a/b/c/d/e/f", 7)]
public void ConcatSegment(string baseRoute, string segment, string expected, int count)
{
- // preconditions
+ // arrange
var route = new RouteEndpoint(baseRoute);
- // test execution
- var concat = route.Concat(segment != null ? [.. segment?.Split('/').Select(x => new UriPathSegmentConstant(x))] : null);
+ // act
+ var concat = route.Concat(segment is not null
+ ? [.. segment?.Split('/').Select(x => new UriPathSegmentConstant(x))]
+ : null);
+ // validation
Assert.Equal(expected, concat.ToString());
Assert.Equal(count, concat.PathSegments.Count());
}
@@ -59,9 +63,10 @@ public void ConcatSegment(string baseRoute, string segment, string expected, int
[InlineData("/a/b/c", "/d/e/f", "/a/b/c/d/e/f")]
public void CombinePath(string baseRoute, string pathB, string expected)
{
- // test execution
+ // act
var combine = RouteEndpoint.Combine([new RouteEndpoint(baseRoute), new RouteEndpoint(pathB)]);
+ // validation
Assert.Equal(expected, combine.ToString());
}
@@ -75,9 +80,10 @@ public void CombinePath(string baseRoute, string pathB, string expected)
[InlineData("/a/b/c", "/d/e/f", "/a/b/c/d/e/f")]
public void CombineRoute(string baseRoute, string pathB, string expected)
{
- // test execution
+ // act
var combine = RouteEndpoint.Combine(new RouteEndpoint(baseRoute), [pathB]);
+ // validation
Assert.Equal(expected, combine.ToString());
}
@@ -91,9 +97,10 @@ public void CombineRoute(string baseRoute, string pathB, string expected)
[InlineData("/a/b/c", "/d/e/f", "/a/b/c/d/e/f")]
public void CombineSegment(string baseRoute, string segment, string expected)
{
- // test execution
+ // act
var combine = RouteEndpoint.Combine(new RouteEndpoint(baseRoute), segment);
+ // validation
Assert.Equal(expected, combine.ToString());
}
@@ -109,11 +116,13 @@ public void CombineSegment(string baseRoute, string segment, string expected)
[InlineData("/a/b/c", "/a/c", "/a/b/c")]
public void RemoveSegment(string route, string segment, string expected)
{
- // test execution
+ // arrange
var routeEndpoint = new RouteEndpoint(route);
+ // act
var removed = routeEndpoint.RemoveSegment(segment);
+ // validation
Assert.Equal(expected, removed.ToString());
}
}
diff --git a/src/WebExpress.WebCore.Test/Route/UnitTestSegmentAttribute.cs b/src/WebExpress.WebCore.Test/Route/UnitTestSegmentAttribute.cs
new file mode 100644
index 0000000..9db7140
--- /dev/null
+++ b/src/WebExpress.WebCore.Test/Route/UnitTestSegmentAttribute.cs
@@ -0,0 +1,131 @@
+using WebExpress.WebCore.WebAttribute;
+
+namespace WebExpress.WebCore.Test.Route
+{
+ ///
+ /// Tests the segment attribute.
+ ///
+ [Collection("NonParallelTests")]
+ public class UnitTestSegmentAttribute
+ {
+ ///
+ /// Test the constant segment.
+ ///
+ [Theory]
+ [InlineData(null, "")]
+ [InlineData("abc", "abc")]
+ public void Constant(string name, string expected)
+ {
+ // arrange
+ var attribute = new SegmentAttribute(name);
+
+ // act
+ var segment = attribute.ToPathSegment();
+
+ // validation
+ Assert.Equal(expected, segment.ToString());
+ }
+
+ ///
+ /// Test the double segment attribute.
+ ///
+ [Theory]
+ [InlineData("${testparametera}")]
+ public void Double(string expected)
+ {
+ // arrange
+ var attribute = new SegmentDoubleAttribute("");
+
+ // act
+ var segment = attribute.ToPathSegment();
+
+ // validation
+ Assert.Equal(expected, segment.ToString());
+ }
+
+ ///
+ /// Test the guid segment attribute.
+ ///
+ [Theory]
+ [InlineData("${testparametera}")]
+ public void Guid(string expected)
+ {
+ // arrange
+ var attribute = new SegmentGuidAttribute();
+
+ // act
+ var segment = attribute.ToPathSegment();
+
+ // validation
+ Assert.Equal(expected, segment.ToString());
+ }
+
+ ///
+ /// Test the int segment attribute.
+ ///
+ [Theory]
+ [InlineData("${testparametera}")]
+ public void Int(string expected)
+ {
+ // arrange
+ var attribute = new SegmentIntAttribute();
+
+ // act
+ var segment = attribute.ToPathSegment();
+
+ // validation
+ Assert.Equal(expected, segment.ToString());
+ }
+
+ ///
+ /// Test the regex segment attribute.
+ ///
+ [Theory]
+ [InlineData(".*", "${testparametera}")]
+ public void Regex(string regex, string expected)
+ {
+ // arrange
+ var attribute = new SegmentRegexAttribute(regex);
+
+ // act
+ var segment = attribute.ToPathSegment();
+
+ // validation
+ Assert.Equal(expected, segment.ToString());
+ }
+
+ ///
+ /// Test the string segment attribute.
+ ///
+ [Theory]
+ [InlineData("${testparametera}")]
+ public void String(string expected)
+ {
+ // arrange
+ var attribute = new SegmentStringAttribute();
+
+ // act
+ var segment = attribute.ToPathSegment();
+
+ // validation
+ Assert.Equal(expected, segment.ToString());
+ }
+
+ ///
+ /// Test the uint segment attribute.
+ ///
+ [Theory]
+ [InlineData("${testparametera}")]
+ public void UInt(string expected)
+ {
+ // arrange
+ var attribute = new SegmentUIntAttribute();
+
+ // act
+ var segment = attribute.ToPathSegment();
+
+ // validation
+ Assert.Equal(expected, segment.ToString());
+ }
+ }
+}
diff --git a/src/WebExpress.WebCore.Test/Route/UnitTestUriPathSegment.cs b/src/WebExpress.WebCore.Test/Route/UnitTestUriPathSegment.cs
new file mode 100644
index 0000000..343198e
--- /dev/null
+++ b/src/WebExpress.WebCore.Test/Route/UnitTestUriPathSegment.cs
@@ -0,0 +1,163 @@
+using WebExpress.WebCore.Test.Fixture;
+using WebExpress.WebCore.WebUri;
+
+namespace WebExpress.WebCore.Test.Route
+{
+ ///
+ /// Tests the path segment.
+ ///
+ [Collection("NonParallelTests")]
+ public class UnitTestUriPathSegment
+ {
+ ///
+ /// Test the constant segment.
+ ///
+ [Theory]
+ [InlineData(null, "", null)]
+ [InlineData("abc", "abc", null)]
+ public void Constant(string value, string expected, string displayText)
+ {
+ // arrange
+ var renderContet = UnitTestFixture.CrerateRenderContextMock();
+
+ // act
+ var segment = new UriPathSegmentConstant(value);
+
+ // validation
+ Assert.Equal(expected, segment.ToString());
+ Assert.Equal(displayText, segment.GetDisplayText(renderContet));
+ }
+
+ ///
+ /// Test the int segment.
+ ///
+ [Theory]
+ [InlineData(null, "${testparametera}", null)]
+ [InlineData("123", "123", "123")]
+ public void Int(string value, string expected, string displayText)
+ {
+ // arrange
+ var renderContet = UnitTestFixture.CrerateRenderContextMock();
+
+ // act
+ var segment = new UriPathSegmentVariableInt()
+ {
+ Value = value
+ };
+
+ // validation
+ Assert.Equal(expected, segment.ToString());
+ Assert.Equal(displayText, segment.GetDisplayText(renderContet));
+ }
+
+ ///
+ /// Test the uint segment.
+ ///
+ [Theory]
+ [InlineData(null, "${testparametera}", null)]
+ [InlineData("123", "123", "123")]
+ public void UInt(string value, string expected, string displayText)
+ {
+ // arrange
+ var renderContet = UnitTestFixture.CrerateRenderContextMock();
+
+ // act
+ var segment = new UriPathSegmentVariableUInt()
+ {
+ Value = value
+ };
+
+ // validation
+ Assert.Equal(expected, segment.ToString());
+ Assert.Equal(displayText, segment.GetDisplayText(renderContet));
+ }
+
+ ///
+ /// Test the double segment.
+ ///
+ [Theory]
+ [InlineData(null, "${testparametera}", null)]
+ [InlineData("123", "123", "123")]
+ public void Double(string value, string expected, string displayText)
+ {
+ // arrange
+ var renderContet = UnitTestFixture.CrerateRenderContextMock();
+
+ // act
+ var segment = new UriPathSegmentVariableDouble()
+ {
+ Value = value
+ };
+
+ // validation
+ Assert.Equal(expected, segment.ToString());
+ Assert.Equal(displayText, segment.GetDisplayText(renderContet));
+ }
+
+ ///
+ /// Test the guid segment.
+ ///
+ [Theory]
+ [InlineData(null, "${testparametera}", null)]
+ [InlineData("123", "123", "")]
+ public void Guid(string value, string expected, string displayText)
+ {
+ // arrange
+ var renderContet = UnitTestFixture.CrerateRenderContextMock();
+
+ // act
+ var segment = new UriPathSegmentVariableGuid()
+ {
+ Value = value
+ };
+
+ // validation
+ Assert.Equal(expected, segment.ToString());
+ Assert.Equal(displayText, segment.GetDisplayText(renderContet));
+ }
+
+ ///
+ /// Test the regex segment.
+ ///
+ [Theory]
+ [InlineData(null, "${testparametera}", null)]
+ [InlineData("123", "123", "123")]
+ public void Regex(string value, string expected, string displayText)
+ {
+ // arrange
+ var renderContet = UnitTestFixture.CrerateRenderContextMock();
+
+ // act
+ var segment = new UriPathSegmentVariableRegex(".*")
+ {
+ Value = value
+ };
+
+ // validation
+ Assert.Equal(expected, segment.ToString());
+ Assert.Equal(displayText, segment.GetDisplayText(renderContet));
+ }
+
+ ///
+ /// Test the regex segment.
+ ///
+ [Theory]
+ [InlineData(null, "${testparametera}", null)]
+ [InlineData("123", "123", "123")]
+ public void String(string value, string expected, string displayText)
+ {
+ // arrange
+ var renderContet = UnitTestFixture.CrerateRenderContextMock();
+
+ // act
+ var segment = new UriPathSegmentVariableString(".*")
+ {
+ Value = value
+ };
+
+ // validation
+ Assert.Equal(expected, segment.ToString());
+ Assert.Equal(displayText, segment.GetDisplayText(renderContet));
+ }
+ }
+}
diff --git a/src/WebExpress.WebCore.Test/Schedule/UnitTestClock.cs b/src/WebExpress.WebCore.Test/Schedule/UnitTestClock.cs
index 004ba48..bb2a209 100644
--- a/src/WebExpress.WebCore.Test/Schedule/UnitTestClock.cs
+++ b/src/WebExpress.WebCore.Test/Schedule/UnitTestClock.cs
@@ -21,7 +21,7 @@ public class UnitTestClock
[InlineData(-1, -10, 0, 0, (24 * 60) + (10 * 60))]
public void Synchronize(int? days, int? hours, int? minutes, int? seconds, int expected)
{
- // preconditions
+ // arrange
var dateTime = DateTime.Now;
if (days.HasValue)
@@ -46,7 +46,7 @@ public void Synchronize(int? days, int? hours, int? minutes, int? seconds, int e
var clock = new Clock(dateTime);
- // test execution
+ // act
var elapsed = clock.Synchronize();
Assert.Equal(expected, elapsed.Count());
@@ -60,11 +60,11 @@ public void Synchronize(int? days, int? hours, int? minutes, int? seconds, int e
[InlineData("2020-12-31 23:59:00", "2021-01-01 00:00:00", false)]
public void CompareEquals(string dateTime1, string dateTime2, bool expected)
{
- // preconditions
+ // arrange
var clock1 = new Clock(DateTime.ParseExact(dateTime1, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));
var clock2 = new Clock(DateTime.ParseExact(dateTime2, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));
- // test execution
+ // act
Assert.Equal(expected, clock1 == clock2);
}
@@ -76,11 +76,11 @@ public void CompareEquals(string dateTime1, string dateTime2, bool expected)
[InlineData("2020-12-31 23:59:00", "2021-01-01 00:00:00", true)]
public void CompareInequality(string dateTime1, string dateTime2, bool expected)
{
- // preconditions
+ // arrange
var clock1 = new Clock(DateTime.ParseExact(dateTime1, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));
var clock2 = new Clock(DateTime.ParseExact(dateTime2, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));
- // test execution
+ // act
Assert.Equal(expected, clock1 != clock2);
}
@@ -93,11 +93,11 @@ public void CompareInequality(string dateTime1, string dateTime2, bool expected)
[InlineData("2020-12-31 23:59:00", "2021-01-01 00:00:00", true)]
public void CompareLess(string dateTime1, string dateTime2, bool expected)
{
- // preconditions
+ // arrange
var clock1 = new Clock(DateTime.ParseExact(dateTime1, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));
var clock2 = new Clock(DateTime.ParseExact(dateTime2, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));
- // test execution
+ // act
Assert.Equal(expected, clock1 < clock2);
}
@@ -110,11 +110,11 @@ public void CompareLess(string dateTime1, string dateTime2, bool expected)
[InlineData("2020-12-31 23:59:00", "2021-01-01 00:00:00", false)]
public void CompareGreater(string dateTime1, string dateTime2, bool expected)
{
- // preconditions
+ // arrange
var clock1 = new Clock(DateTime.ParseExact(dateTime1, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));
var clock2 = new Clock(DateTime.ParseExact(dateTime2, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));
- // test execution
+ // act
Assert.Equal(expected, clock1 > clock2);
}
@@ -127,11 +127,11 @@ public void CompareGreater(string dateTime1, string dateTime2, bool expected)
[InlineData("2020-12-31 23:59:00", "2021-01-01 00:00:00", true)]
public void CompareLessOrEqual(string dateTime1, string dateTime2, bool expected)
{
- // preconditions
+ // arrange
var clock1 = new Clock(DateTime.ParseExact(dateTime1, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));
var clock2 = new Clock(DateTime.ParseExact(dateTime2, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));
- // test execution
+ // act
Assert.Equal(expected, clock1 <= clock2);
}
@@ -144,11 +144,11 @@ public void CompareLessOrEqual(string dateTime1, string dateTime2, bool expected
[InlineData("2020-12-31 23:59:00", "2021-01-01 00:00:00", false)]
public void CompareGreaterOrEqual(string dateTime1, string dateTime2, bool expected)
{
- // preconditions
+ // arrange
var clock1 = new Clock(DateTime.ParseExact(dateTime1, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));
var clock2 = new Clock(DateTime.ParseExact(dateTime2, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));
- // test execution
+ // act
Assert.Equal(expected, clock1 >= clock2);
}
@@ -167,7 +167,7 @@ public void Tick(string dateTime1, string expected)
var clock2 = new Clock(DateTime.ParseExact(expected, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));
clock1.Tick();
- // test execution
+ // act
Assert.Equal(clock2, clock1);
}
}
diff --git a/src/WebExpress.WebCore.Test/Schedule/UnitTestCron.cs b/src/WebExpress.WebCore.Test/Schedule/UnitTestCron.cs
index 65a1400..4053e43 100644
--- a/src/WebExpress.WebCore.Test/Schedule/UnitTestCron.cs
+++ b/src/WebExpress.WebCore.Test/Schedule/UnitTestCron.cs
@@ -13,45 +13,45 @@ public class UnitTestCron
[Fact]
public void Create_1()
{
- // preconditions
+ // arrange
var context = UnitTestFixture.CreateHttpServerContextMock();
var clock = new Clock();
var cron = new Cron(context, "0-59", "*", "1-31", "1-2,3,4,5,6,7,8-10,11,12");
- // test execution
+ // act
Assert.True(cron.Matching(clock));
}
[Fact]
public void Create_2()
{
- // preconditions
+ // arrange
var context = UnitTestFixture.CreateHttpServerContextMock();
var dateTime = DateTime.Now;
var clock = new Clock(new DateTime(dateTime.Year, 1, dateTime.Day, dateTime.Hour, dateTime.Minute, 0));
var cron = new Cron(context, "*", "*", "0-33", "2, 1-4, x");
- // test execution
+ // act
Assert.True(cron.Matching(clock));
}
[Fact]
public void Create_3()
{
- // preconditions
+ // arrange
var context = UnitTestFixture.CreateHttpServerContextMock();
var dateTime = DateTime.Now;
var clock = new Clock(new DateTime(dateTime.Year, 12, 31, dateTime.Hour, dateTime.Minute, 0));
var cron = new Cron(context, "*", "*", "31", "12");
- // test execution
+ // act
Assert.True(cron.Matching(clock));
}
[Fact]
public void Create_4()
{
- // preconditions
+ // arrange
var context = UnitTestFixture.CreateHttpServerContextMock();
var dateTime = DateTime.Now;
Log.Current.Clear();
@@ -59,27 +59,27 @@ public void Create_4()
var clock = new Clock(new DateTime(dateTime.Year, 12, 31, dateTime.Hour, dateTime.Minute, 0));
var cron = new Cron(context, "*", "*", "*", "a");
- // test execution
+ // act
Assert.Equal(1, context.Log.WarningCount);
}
[Fact]
public void Create_5()
{
- // preconditions
+ // arrange
var context = UnitTestFixture.CreateHttpServerContextMock();
var dateTime = DateTime.Now;
var clock = new Clock(new DateTime(dateTime.Year, 12, 31, dateTime.Hour, dateTime.Minute, 0));
var cron = new Cron(context, "*", "*", "*", "");
- // test execution
+ // act
Assert.True(cron.Matching(clock));
}
[Fact]
public void Create_6()
{
- // preconditions
+ // arrange
var context = UnitTestFixture.CreateHttpServerContextMock();
var dateTime = DateTime.Now;
Log.Current.Clear();
@@ -87,46 +87,46 @@ public void Create_6()
var clock = new Clock(new DateTime(dateTime.Year, 12, 31, dateTime.Hour, dateTime.Minute, 0));
var cron = new Cron(context, "99", "*", "*", "*");
- // test execution
+ // act
Assert.Equal(1, context.Log.WarningCount);
}
[Fact]
public void Matching_1()
{
- // preconditions
+ // arrange
var context = UnitTestFixture.CreateHttpServerContextMock();
var dateTime = DateTime.Now;
var clock = new Clock(new DateTime(dateTime.Year, 12, 31, dateTime.Hour, dateTime.Minute, 0));
var cron = new Cron(context, "*", "*", "31", "1-11");
- // test execution
+ // act
Assert.False(cron.Matching(clock));
}
[Fact]
public void Matching_2()
{
- // preconditions
+ // arrange
var context = UnitTestFixture.CreateHttpServerContextMock();
var dateTime = DateTime.Now;
var clock = new Clock(new DateTime(2020, 1, 1, dateTime.Hour, dateTime.Minute, 0)); // wednesday
var cron = new Cron(context, "*", "*", "*", "*", "3"); // wednesday
- // test execution
+ // act
Assert.True(cron.Matching(clock));
}
[Fact]
public void Matching_3()
{
- // preconditions
+ // arrange
var context = UnitTestFixture.CreateHttpServerContextMock();
var dateTime = DateTime.Now;
var clock = new Clock(new DateTime(2020, 1, 1, dateTime.Hour, dateTime.Minute, 0)); // wednesday
var cron = new Cron(context, "*", "*", "*", "*", "1"); // sunday
- // test execution
+ // act
Assert.False(cron.Matching(clock));
}
}
diff --git a/src/WebExpress.WebCore.Test/TestApplicationA.cs b/src/WebExpress.WebCore.Test/TestApplicationA.cs
index 5b687a7..4e8c0c8 100644
--- a/src/WebExpress.WebCore.Test/TestApplicationA.cs
+++ b/src/WebExpress.WebCore.Test/TestApplicationA.cs
@@ -22,7 +22,7 @@ public sealed class TestApplicationA : IApplication
private TestApplicationA(IApplicationContext applicationContext)
{
// test the injection
- if (applicationContext == null)
+ if (applicationContext is null)
{
throw new ArgumentNullException(nameof(applicationContext), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/TestApplicationC.cs b/src/WebExpress.WebCore.Test/TestApplicationC.cs
index 5adfc91..62f2f66 100644
--- a/src/WebExpress.WebCore.Test/TestApplicationC.cs
+++ b/src/WebExpress.WebCore.Test/TestApplicationC.cs
@@ -22,13 +22,13 @@ public sealed class TestApplicationC : IApplication
private TestApplicationC(IApplicationContext applicationContext, IPluginManager pluginManager)
{
// test the injection
- if (applicationContext == null)
+ if (applicationContext is null)
{
throw new ArgumentNullException(nameof(applicationContext), "Parameter cannot be null or empty.");
}
// test the injection
- if (pluginManager == null)
+ if (pluginManager is null)
{
throw new ArgumentNullException(nameof(pluginManager), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/TestConditionAlwaysFalse.cs b/src/WebExpress.WebCore.Test/TestConditionAlwaysFalse.cs
index c77a1c1..fa9ff3e 100644
--- a/src/WebExpress.WebCore.Test/TestConditionAlwaysFalse.cs
+++ b/src/WebExpress.WebCore.Test/TestConditionAlwaysFalse.cs
@@ -13,7 +13,7 @@ public class TestConditionAlwaysFalse : ICondition
///
/// The request.
/// True if the condition is fulfilled, false otherwise.
- public bool Fulfillment(Request request)
+ public bool Fulfillment(IRequest request)
{
return false;
}
diff --git a/src/WebExpress.WebCore.Test/TestEventHandlerA.cs b/src/WebExpress.WebCore.Test/TestEventHandlerA.cs
index c93ae04..97c8fdf 100644
--- a/src/WebExpress.WebCore.Test/TestEventHandlerA.cs
+++ b/src/WebExpress.WebCore.Test/TestEventHandlerA.cs
@@ -19,13 +19,13 @@ public sealed class TestEventHandlerA : IEventHandler
private TestEventHandlerA(IEventHandlerContext eventHandlerContext, IApplicationManager applicationManager)
{
// test the injection
- if (eventHandlerContext == null)
+ if (eventHandlerContext is null)
{
throw new ArgumentNullException(nameof(eventHandlerContext), "Parameter cannot be null or empty.");
}
// test the injection
- if (applicationManager == null)
+ if (applicationManager is null)
{
throw new ArgumentNullException(nameof(applicationManager), "Parameter cannot be null or empty.");
}
@@ -39,13 +39,13 @@ private TestEventHandlerA(IEventHandlerContext eventHandlerContext, IApplication
public void Process(object sender, IEventArgument eventArgument)
{
// test the parameter
- if (sender == null)
+ if (sender is null)
{
throw new ArgumentNullException(nameof(sender), "Parameter cannot be null or empty.");
}
// test the parameter
- if (eventArgument == null)
+ if (eventArgument is null)
{
throw new ArgumentNullException(nameof(eventArgument), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/TestEventHandlerB.cs b/src/WebExpress.WebCore.Test/TestEventHandlerB.cs
index 542d528..b375a70 100644
--- a/src/WebExpress.WebCore.Test/TestEventHandlerB.cs
+++ b/src/WebExpress.WebCore.Test/TestEventHandlerB.cs
@@ -19,13 +19,13 @@ public sealed class TestEventHandlerB : IEventHandler
private TestEventHandlerB(IEventHandlerContext eventHandlerContext, IApplicationManager applicationManager)
{
// test the injection
- if (eventHandlerContext == null)
+ if (eventHandlerContext is null)
{
throw new ArgumentNullException(nameof(eventHandlerContext), "Parameter cannot be null or empty.");
}
// test the injection
- if (applicationManager == null)
+ if (applicationManager is null)
{
throw new ArgumentNullException(nameof(applicationManager), "Parameter cannot be null or empty.");
}
@@ -39,13 +39,13 @@ private TestEventHandlerB(IEventHandlerContext eventHandlerContext, IApplication
public void Process(object sender, TestEventArgument eventArgument)
{
// test the parameter
- if (sender == null)
+ if (sender is null)
{
throw new ArgumentNullException(nameof(sender), "Parameter cannot be null or empty.");
}
// test the parameter
- if (eventArgument == null)
+ if (eventArgument is null)
{
throw new ArgumentNullException(nameof(eventArgument), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/TestFragmentA.cs b/src/WebExpress.WebCore.Test/TestFragmentA.cs
index 8fb3a7a..0fda54e 100644
--- a/src/WebExpress.WebCore.Test/TestFragmentA.cs
+++ b/src/WebExpress.WebCore.Test/TestFragmentA.cs
@@ -30,13 +30,13 @@ public sealed class TestFragmentA : IFragment
public TestFragmentA(IComponentHub componentHub, IFragmentContext fragmentContext, IComponentId id)
{
// test the injection
- if (componentHub == null)
+ if (componentHub is null)
{
throw new ArgumentNullException(nameof(componentHub), "Parameter componentHub cannot be null or empty.");
}
// test the injection
- if (fragmentContext == null)
+ if (fragmentContext is null)
{
throw new ArgumentNullException(nameof(fragmentContext), "Parameter fragmentContext cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/TestFragmentB.cs b/src/WebExpress.WebCore.Test/TestFragmentB.cs
index 88a58c6..0f179d9 100644
--- a/src/WebExpress.WebCore.Test/TestFragmentB.cs
+++ b/src/WebExpress.WebCore.Test/TestFragmentB.cs
@@ -27,13 +27,13 @@ public sealed class TestFragmentB : IFragment
public TestFragmentB(IComponentHub componentHub, IFragmentContext fragmentContext)
{
// test the injection
- if (componentHub == null)
+ if (componentHub is null)
{
throw new ArgumentNullException(nameof(componentHub), "Parameter cannot be null or empty.");
}
// test the injection
- if (fragmentContext == null)
+ if (fragmentContext is null)
{
throw new ArgumentNullException(nameof(fragmentContext), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/TestFragmentC.cs b/src/WebExpress.WebCore.Test/TestFragmentC.cs
index 40be3f3..7f4281f 100644
--- a/src/WebExpress.WebCore.Test/TestFragmentC.cs
+++ b/src/WebExpress.WebCore.Test/TestFragmentC.cs
@@ -26,13 +26,13 @@ public sealed class TestFragmentC : IFragment
public TestFragmentC(IComponentHub componentHub, IFragmentContext fragmentContext)
{
// test the injection
- if (componentHub == null)
+ if (componentHub is null)
{
throw new ArgumentNullException(nameof(componentHub), "Parameter cannot be null or empty.");
}
// test the injection
- if (fragmentContext == null)
+ if (fragmentContext is null)
{
throw new ArgumentNullException(nameof(fragmentContext), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/TestFragmentD.cs b/src/WebExpress.WebCore.Test/TestFragmentD.cs
index 3a583fd..913287e 100644
--- a/src/WebExpress.WebCore.Test/TestFragmentD.cs
+++ b/src/WebExpress.WebCore.Test/TestFragmentD.cs
@@ -27,13 +27,13 @@ public sealed class TestFragmentD : IFragment
public TestFragmentD(IComponentHub componentHub, IFragmentContext fragmentContext)
{
// test the injection
- if (componentHub == null)
+ if (componentHub is null)
{
throw new ArgumentNullException(nameof(componentHub), "Parameter cannot be null or empty.");
}
// test the injection
- if (fragmentContext == null)
+ if (fragmentContext is null)
{
throw new ArgumentNullException(nameof(fragmentContext), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/TestJobA.cs b/src/WebExpress.WebCore.Test/TestJobA.cs
index 8794b38..1351db7 100644
--- a/src/WebExpress.WebCore.Test/TestJobA.cs
+++ b/src/WebExpress.WebCore.Test/TestJobA.cs
@@ -16,7 +16,7 @@ public sealed class TestJobA : IJob
private TestJobA(IJobContext jobContext)
{
// test the injection
- if (jobContext == null)
+ if (jobContext is null)
{
throw new ArgumentNullException(nameof(jobContext), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/TestParameterA.cs b/src/WebExpress.WebCore.Test/TestParameterA.cs
index e77468b..9896cf7 100644
--- a/src/WebExpress.WebCore.Test/TestParameterA.cs
+++ b/src/WebExpress.WebCore.Test/TestParameterA.cs
@@ -1,19 +1,33 @@
-using WebExpress.WebCore.WebMessage;
+using WebExpress.WebCore.WebParameter;
namespace WebExpress.WebCore.Test
{
///
/// Represents a test parameter.
///
- internal class TestParameterA : Parameter
+ internal class TestParameterA : IParameterStatic
{
+ ///
+ /// Returns the key that uniquely identifies the parameter in configuration or
+ /// settings contexts.
+ ///
+ public static string Key => "testparametera";
+
+ ///
+ /// Returns or sets the scope of the parameter.
+ ///
+ public ParameterScope Scope { get; set; }
+
+ ///
+ /// Returns the value of the parameter.
+ ///
+ public string Value { get; set; }
+
///
/// Initializes a new instance of the class.
///
public TestParameterA()
- : base("TestParameterA", null, ParameterScope.Url)
{
-
}
///
@@ -21,9 +35,8 @@ public TestParameterA()
///
/// The value of the parameter.
public TestParameterA(int value)
- : base("TestParameterA", value, ParameterScope.Url)
{
-
+ Value = value.ToString();
}
///
@@ -31,9 +44,20 @@ public TestParameterA(int value)
///
/// The value of the parameter.
public TestParameterA(Guid value)
- : base("TestParameterA", value.ToString(), ParameterScope.Url)
{
+ Value = value.ToString();
+ }
+ ///
+ /// Retrieves the unique key associated with the current instance.
+ ///
+ ///
+ /// A string representing the unique key. This key is used for identifying
+ /// the instance in various operations.
+ ///
+ public string GetKey()
+ {
+ return Key;
}
}
}
diff --git a/src/WebExpress.WebCore.Test/TestParameterB.cs b/src/WebExpress.WebCore.Test/TestParameterB.cs
new file mode 100644
index 0000000..a28e0da
--- /dev/null
+++ b/src/WebExpress.WebCore.Test/TestParameterB.cs
@@ -0,0 +1,61 @@
+using WebExpress.WebCore.WebParameter;
+
+namespace WebExpress.WebCore.Test
+{
+ ///
+ /// Represents a test parameter.
+ ///
+ internal class TestParameterB : IParameterStatic
+ {
+ //
+ /// Returns the key that uniquely identifies the parameter in configuration or
+ /// settings contexts.
+ ///
+ public static string Key => "testparameterb";
+
+ ///
+ /// Returns or sets the scope of the parameter.
+ ///
+ public ParameterScope Scope { get; set; }
+
+ ///
+ /// Returns the value of the parameter.
+ ///
+ public string Value { get; set; }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public TestParameterB()
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class with a specified value.
+ ///
+ /// The value of the parameter.
+ public TestParameterB(int value)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class with a specified value.
+ ///
+ /// The value of the parameter.
+ public TestParameterB(Guid value)
+ {
+ }
+
+ ///
+ /// Retrieves the unique key associated with the current instance.
+ ///
+ ///
+ /// A string representing the unique key. This key is used for identifying
+ /// the instance in various operations.
+ ///
+ public string GetKey()
+ {
+ return Key;
+ }
+ }
+}
diff --git a/src/WebExpress.WebCore.Test/TestRenderContext.cs b/src/WebExpress.WebCore.Test/TestRenderContext.cs
index 5b84420..35d6d4c 100644
--- a/src/WebExpress.WebCore.Test/TestRenderContext.cs
+++ b/src/WebExpress.WebCore.Test/TestRenderContext.cs
@@ -22,7 +22,7 @@ public class TestRenderContext : IRenderContext
///
/// Returns the request.
///
- public Request Request { get; protected set; }
+ public IRequest Request { get; protected set; }
///
/// Initializes a new instance of the class.
@@ -30,7 +30,7 @@ public class TestRenderContext : IRenderContext
/// The endpoint associated with the rendering context.
/// >The page context.
/// The request associated with the rendering context.
- public TestRenderContext(IEndpoint endpoint, IPageContext pageContext, Request request)
+ public TestRenderContext(IEndpoint endpoint, IPageContext pageContext, IRequest request)
{
Endpoint = endpoint;
PageContext = pageContext;
diff --git a/src/WebExpress.WebCore.Test/TestSocketA.cs b/src/WebExpress.WebCore.Test/TestSocketA.cs
new file mode 100644
index 0000000..e3f70d5
--- /dev/null
+++ b/src/WebExpress.WebCore.Test/TestSocketA.cs
@@ -0,0 +1,45 @@
+using WebExpress.WebCore.WebSocket;
+
+namespace WebExpress.WebCore.Test
+{
+ ///
+ /// A dummy web socket for testing purposes.
+ ///
+ public sealed class TestSocketA : ISocket
+ {
+ private readonly ISocketContext _socketContext;
+
+ ///
+ /// Initializes a new instance of the TestSocketA class using the specified
+ /// socket context and write stream.
+ ///
+ ///
+ /// The socket context that manages the state and configuration for the socket
+ /// connection.
+ ///
+ /// The connection id.
+ public TestSocketA(ISocketContext socketContext, Guid connectionId)
+ {
+ _socketContext = socketContext ?? throw new ArgumentNullException(nameof(socketContext), "Parameter cannot be null or empty.");
+ }
+
+ ///
+ /// Handles logic to be executed when a new connection is established with the
+ /// socket server.
+ ///
+ /// The socket connection.
+ ///
+ /// A task that represents the asynchronous operation.
+ ///
+ public async Task OnConnectedAsync(ISocketConnection socketConnection)
+ {
+ }
+
+ ///
+ /// Releases all resources used by the current instance of the class.
+ ///
+ public void Dispose()
+ {
+ }
+ }
+}
diff --git a/src/WebExpress.WebCore.Test/TestStatusPage301.cs b/src/WebExpress.WebCore.Test/TestStatusPage301.cs
index ad41698..97617eb 100644
--- a/src/WebExpress.WebCore.Test/TestStatusPage301.cs
+++ b/src/WebExpress.WebCore.Test/TestStatusPage301.cs
@@ -20,7 +20,7 @@ public sealed class TestStatusPage301 : IStatusPage
private TestStatusPage301(IStatusPageContext statusPageContext)
{
// test the injection
- if (statusPageContext == null)
+ if (statusPageContext is null)
{
throw new ArgumentNullException(nameof(statusPageContext), "Parameter cannot be null or empty.");
}
@@ -34,7 +34,7 @@ private TestStatusPage301(IStatusPageContext statusPageContext)
public void Process(IRenderContext renderContext, VisualTree visualTree)
{
// test the parameter
- if (renderContext == null)
+ if (renderContext is null)
{
throw new ArgumentNullException(nameof(renderContext), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/TestStatusPage400.cs b/src/WebExpress.WebCore.Test/TestStatusPage400.cs
index c005266..0243af1 100644
--- a/src/WebExpress.WebCore.Test/TestStatusPage400.cs
+++ b/src/WebExpress.WebCore.Test/TestStatusPage400.cs
@@ -27,13 +27,13 @@ public sealed class TestStatusPage400 : IStatusPage
private TestStatusPage400(IStatusPageContext statusPageContext, StatusMessage message)
{
// test the injection
- if (statusPageContext == null)
+ if (statusPageContext is null)
{
throw new ArgumentNullException(nameof(statusPageContext), "Parameter cannot be null or empty.");
}
// test the injection
- if (message == null)
+ if (message is null)
{
throw new ArgumentNullException(nameof(message), "Parameter cannot be null or empty.");
}
@@ -49,7 +49,7 @@ private TestStatusPage400(IStatusPageContext statusPageContext, StatusMessage me
public void Process(IRenderContext renderContext, VisualTree visualTree)
{
// test the parameter
- if (renderContext == null)
+ if (renderContext is null)
{
throw new ArgumentNullException(nameof(renderContext), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/TestStatusPage404.cs b/src/WebExpress.WebCore.Test/TestStatusPage404.cs
index ab0bea6..09165f4 100644
--- a/src/WebExpress.WebCore.Test/TestStatusPage404.cs
+++ b/src/WebExpress.WebCore.Test/TestStatusPage404.cs
@@ -20,7 +20,7 @@ public sealed class TestStatusPage404 : IStatusPage
private TestStatusPage404(IStatusPageContext statusPageContext)
{
// test the injection
- if (statusPageContext == null)
+ if (statusPageContext is null)
{
throw new ArgumentNullException(nameof(statusPageContext), "Parameter cannot be null or empty.");
}
@@ -34,7 +34,7 @@ private TestStatusPage404(IStatusPageContext statusPageContext)
public void Process(IRenderContext renderContext, VisualTree visualTree)
{
// test the parameter
- if (renderContext == null)
+ if (renderContext is null)
{
throw new ArgumentNullException(nameof(renderContext), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/TestStatusPage500.cs b/src/WebExpress.WebCore.Test/TestStatusPage500.cs
index f283612..8d585fa 100644
--- a/src/WebExpress.WebCore.Test/TestStatusPage500.cs
+++ b/src/WebExpress.WebCore.Test/TestStatusPage500.cs
@@ -27,13 +27,13 @@ public sealed class TestStatusPage500 : IStatusPage
private TestStatusPage500(IStatusPageContext statusPageContext, StatusMessage message)
{
// test the injection
- if (statusPageContext == null)
+ if (statusPageContext is null)
{
throw new ArgumentNullException(nameof(statusPageContext), "Parameter cannot be null or empty.");
}
// test the injection
- if (message == null)
+ if (message is null)
{
throw new ArgumentNullException(nameof(message), "Parameter cannot be null or empty.");
}
@@ -49,7 +49,7 @@ private TestStatusPage500(IStatusPageContext statusPageContext, StatusMessage me
public void Process(IRenderContext renderContext, VisualTree visualTree)
{
// test the parameter
- if (renderContext == null)
+ if (renderContext is null)
{
throw new ArgumentNullException(nameof(renderContext), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/TestTask.cs b/src/WebExpress.WebCore.Test/TestTask.cs
index bfb27a3..5c7d70e 100644
--- a/src/WebExpress.WebCore.Test/TestTask.cs
+++ b/src/WebExpress.WebCore.Test/TestTask.cs
@@ -17,17 +17,17 @@ public TestTask(IComponentHub componentHub, string id, params object[] args)
: base(id, args)
{
// test the injection
- if (componentHub == null)
+ if (componentHub is null)
{
throw new ArgumentNullException(nameof(componentHub), "Parameter cannot be null or empty.");
}
- if (id == null)
+ if (id is null)
{
throw new ArgumentNullException(nameof(id), "Parameter cannot be null or empty.");
}
- if (args == null)
+ if (args is null)
{
throw new ArgumentNullException(nameof(args), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/TestVisualTree.cs b/src/WebExpress.WebCore.Test/TestVisualTree.cs
index 4509ae9..bab7aa8 100644
--- a/src/WebExpress.WebCore.Test/TestVisualTree.cs
+++ b/src/WebExpress.WebCore.Test/TestVisualTree.cs
@@ -108,8 +108,10 @@ public virtual IHtmlNode Render(IVisualTreeContext context)
html.Body.Add(Content);
html.Body.Scripts = [.. Scripts.Values];
- html.Head.CssLinks = CssLinks.Where(x => x != null).Select(x => x.ToString());
- html.Head.ScriptLinks = HeaderScriptLinks?.Where(x => x != null).Select(x => x.ToString());
+ html.Head.CssLinks = CssLinks.Where(x => x is not null)
+ .Select(x => x.ToString());
+ html.Head.ScriptLinks = HeaderScriptLinks?.Where(x => x is not null)
+ .Select(x => x.ToString());
return html;
}
diff --git a/src/WebExpress.WebCore.Test/WWW/About.cs b/src/WebExpress.WebCore.Test/WWW/About.cs
index a3326d4..5cdaff6 100644
--- a/src/WebExpress.WebCore.Test/WWW/About.cs
+++ b/src/WebExpress.WebCore.Test/WWW/About.cs
@@ -29,7 +29,7 @@ public About(IPageContext pageContext)
PageContext = pageContext;
// test the injection
- if (pageContext == null)
+ if (pageContext is null)
{
throw new ArgumentNullException(nameof(pageContext), "Parameter cannot be null or empty.");
}
@@ -43,7 +43,7 @@ public About(IPageContext pageContext)
public void Process(IRenderContext renderContext, VisualTree visualTree)
{
// test the context
- if (renderContext == null)
+ if (renderContext is null)
{
throw new ArgumentNullException(nameof(renderContext), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/WWW/Api/1/TestRestApiA.cs b/src/WebExpress.WebCore.Test/WWW/Api/_1_/TestRestApiA.cs
similarity index 92%
rename from src/WebExpress.WebCore.Test/WWW/Api/1/TestRestApiA.cs
rename to src/WebExpress.WebCore.Test/WWW/Api/_1_/TestRestApiA.cs
index 769e67a..4d110b4 100644
--- a/src/WebExpress.WebCore.Test/WWW/Api/1/TestRestApiA.cs
+++ b/src/WebExpress.WebCore.Test/WWW/Api/_1_/TestRestApiA.cs
@@ -3,13 +3,11 @@
using WebExpress.WebCore.WebRestApi;
using WebExpress.WebCore.WebStatusPage;
-namespace WebExpress.WebCore.Test.WWW.Api._1
+namespace WebExpress.WebCore.Test.WWW.Api._1_
{
///
/// A dummy class for testing purposes.
///
- [Method(CrudMethod.POST)]
- [Method(CrudMethod.GET)]
public sealed class TestRestApiA : IRestApi
{
///
@@ -19,7 +17,7 @@ public sealed class TestRestApiA : IRestApi
public TestRestApiA(IRestApiContext restApiContext)
{
// test the injection
- if (restApiContext == null)
+ if (restApiContext is null)
{
throw new ArgumentNullException(nameof(restApiContext), "Parameter cannot be null or empty.");
}
@@ -40,6 +38,7 @@ public Response CreateData(Request request)
///
/// The request.
/// The response containing the result of the operation.
+ [Method(RequestMethod.GET)]
public Response GetData(Request request)
{
return new ResponseBadRequest(new StatusMessage("Not implemented."));
@@ -50,10 +49,11 @@ public Response GetData(Request request)
///
/// The request.
/// The response containing the result of the operation.
+ [Method(RequestMethod.POST)]
public Response UpdateData(Request request)
{
// test the request
- if (request == null)
+ if (request is null)
{
throw new ArgumentNullException(nameof(request), "Parameter cannot be null or empty.");
}
@@ -69,7 +69,7 @@ public Response UpdateData(Request request)
public Response DeleteData(Request request)
{
// test the request
- if (request == null)
+ if (request is null)
{
throw new ArgumentNullException(nameof(request), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/WWW/Api/2/TestRestApiB.cs b/src/WebExpress.WebCore.Test/WWW/Api/_2/TestRestApiB.cs
similarity index 95%
rename from src/WebExpress.WebCore.Test/WWW/Api/2/TestRestApiB.cs
rename to src/WebExpress.WebCore.Test/WWW/Api/_2/TestRestApiB.cs
index d243db1..d5ef343 100644
--- a/src/WebExpress.WebCore.Test/WWW/Api/2/TestRestApiB.cs
+++ b/src/WebExpress.WebCore.Test/WWW/Api/_2/TestRestApiB.cs
@@ -8,7 +8,6 @@ namespace WebExpress.WebCore.Test.WWW.Api._2
///
/// A dummy class for testing purposes.
///
- [Method(CrudMethod.GET)]
public sealed class TestRestApiB : IRestApi
{
///
@@ -18,7 +17,7 @@ public sealed class TestRestApiB : IRestApi
public TestRestApiB(IRestApiContext restApiContext)
{
// test the injection
- if (restApiContext == null)
+ if (restApiContext is null)
{
throw new ArgumentNullException(nameof(restApiContext), "Parameter cannot be null or empty.");
}
@@ -39,6 +38,7 @@ public Response CreateData(Request request)
///
/// The request.
/// The response containing the result of the operation.
+ [Method(RequestMethod.GET)]
public Response GetData(Request request)
{
return new ResponseBadRequest(new StatusMessage("Not implemented."));
@@ -52,7 +52,7 @@ public Response GetData(Request request)
public Response UpdateData(Request request)
{
// test the request
- if (request == null)
+ if (request is null)
{
throw new ArgumentNullException(nameof(request), "Parameter cannot be null or empty.");
}
@@ -68,7 +68,7 @@ public Response UpdateData(Request request)
public Response DeleteData(Request request)
{
// test the request
- if (request == null)
+ if (request is null)
{
throw new ArgumentNullException(nameof(request), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/WWW/Api/3/TestRestApiC.cs b/src/WebExpress.WebCore.Test/WWW/Api/_3_/TestRestApiC.cs
similarity index 78%
rename from src/WebExpress.WebCore.Test/WWW/Api/3/TestRestApiC.cs
rename to src/WebExpress.WebCore.Test/WWW/Api/_3_/TestRestApiC.cs
index 9b499f1..67c5c75 100644
--- a/src/WebExpress.WebCore.Test/WWW/Api/3/TestRestApiC.cs
+++ b/src/WebExpress.WebCore.Test/WWW/Api/_3_/TestRestApiC.cs
@@ -4,13 +4,12 @@
using WebExpress.WebCore.WebRestApi;
using WebExpress.WebCore.WebStatusPage;
-namespace WebExpress.WebCore.Test.WWW.Api._3
+namespace WebExpress.WebCore.Test.WWW.Api.V3
{
///
/// A dummy class for testing purposes.
///
- [Method(CrudMethod.GET)]
- public sealed class TestRestApiC : RestApi
+ public sealed class TestRestApiC : IRestApi
{
///
/// Initialization of the rest api resource. Here, for example, managed resources can be loaded.
@@ -18,16 +17,15 @@ public sealed class TestRestApiC : RestApi
/// The component hub.
/// The context of the restapi resource.
public TestRestApiC(IComponentHub componentHub, IRestApiContext restApiContext)
- : base(restApiContext)
{
// test the injection
- if (componentHub == null)
+ if (componentHub is null)
{
throw new ArgumentNullException(nameof(componentHub), "Parameter cannot be null or empty.");
}
// test the injection
- if (restApiContext == null)
+ if (restApiContext is null)
{
throw new ArgumentNullException(nameof(restApiContext), "Parameter cannot be null or empty.");
}
@@ -38,7 +36,7 @@ public TestRestApiC(IComponentHub componentHub, IRestApiContext restApiContext)
///
/// The request.
/// The response containing the result of the operation.
- public override Response CreateData(Request request)
+ public Response CreateData(Request request)
{
return new ResponseBadRequest(new StatusMessage("Not implemented."));
}
@@ -48,7 +46,8 @@ public override Response CreateData(Request request)
///
/// The request.
/// The response containing the result of the operation.
- public override Response GetData(Request request)
+ [Method(RequestMethod.GET)]
+ public Response GetData(Request request)
{
return new ResponseBadRequest(new StatusMessage("Not implemented."));
}
@@ -58,10 +57,10 @@ public override Response GetData(Request request)
///
/// The request.
/// The response containing the result of the operation.
- public override Response UpdateData(Request request)
+ public Response UpdateData(Request request)
{
// test the request
- if (request == null)
+ if (request is null)
{
throw new ArgumentNullException(nameof(request), "Parameter cannot be null or empty.");
}
@@ -74,22 +73,15 @@ public override Response UpdateData(Request request)
///
/// The request.
/// The response containing the result of the operation.
- public override Response DeleteData(Request request)
+ public Response DeleteData(Request request)
{
// test the request
- if (request == null)
+ if (request is null)
{
throw new ArgumentNullException(nameof(request), "Parameter cannot be null or empty.");
}
return new ResponseBadRequest(new StatusMessage("Not implemented."));
}
-
- ///
- /// Release of unmanaged resources reserved during use.
- ///
- public override void Dispose()
- {
- }
}
}
diff --git a/src/WebExpress.WebCore.Test/WWW/Blog/Index.cs b/src/WebExpress.WebCore.Test/WWW/Blog/Index.cs
index ae60598..1115178 100644
--- a/src/WebExpress.WebCore.Test/WWW/Blog/Index.cs
+++ b/src/WebExpress.WebCore.Test/WWW/Blog/Index.cs
@@ -16,7 +16,7 @@ public sealed class Index : Page
private Index(IPageContext pageContext)
{
// test the injection
- if (pageContext == null)
+ if (pageContext is null)
{
throw new ArgumentNullException(nameof(pageContext), "Parameter cannot be null or empty.");
}
@@ -30,13 +30,13 @@ private Index(IPageContext pageContext)
public override void Process(IRenderContext renderContext, TestVisualTree visualTree)
{
// test the context
- if (renderContext == null)
+ if (renderContext is null)
{
throw new ArgumentNullException(nameof(renderContext), "Parameter cannot be null or empty.");
}
// test the visualTree
- if (visualTree == null)
+ if (visualTree is null)
{
throw new ArgumentNullException(nameof(visualTree), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/WWW/Blog/Post/Add.cs b/src/WebExpress.WebCore.Test/WWW/Blog/Post/Add.cs
index 6f74a0c..413ef93 100644
--- a/src/WebExpress.WebCore.Test/WWW/Blog/Post/Add.cs
+++ b/src/WebExpress.WebCore.Test/WWW/Blog/Post/Add.cs
@@ -16,7 +16,7 @@ public sealed class Add : Page
private Add(IPageContext pageContext)
{
// test the injection
- if (pageContext == null)
+ if (pageContext is null)
{
throw new ArgumentNullException(nameof(pageContext), "Parameter cannot be null or empty.");
}
@@ -30,13 +30,13 @@ private Add(IPageContext pageContext)
public override void Process(IRenderContext renderContext, TestVisualTree visualTree)
{
// test the context
- if (renderContext == null)
+ if (renderContext is null)
{
throw new ArgumentNullException(nameof(renderContext), "Parameter cannot be null or empty.");
}
// test the visualTree
- if (visualTree == null)
+ if (visualTree is null)
{
throw new ArgumentNullException(nameof(visualTree), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/WWW/Blog/Post/Index.cs b/src/WebExpress.WebCore.Test/WWW/Blog/Post/Index.cs
index f9f9098..39cb3be 100644
--- a/src/WebExpress.WebCore.Test/WWW/Blog/Post/Index.cs
+++ b/src/WebExpress.WebCore.Test/WWW/Blog/Post/Index.cs
@@ -16,7 +16,7 @@ public sealed class Index : Page
private Index(IPageContext pageContext)
{
// test the injection
- if (pageContext == null)
+ if (pageContext is null)
{
throw new ArgumentNullException(nameof(pageContext), "Parameter cannot be null or empty.");
}
@@ -30,13 +30,13 @@ private Index(IPageContext pageContext)
public override void Process(IRenderContext renderContext, TestVisualTree visualTree)
{
// test the context
- if (renderContext == null)
+ if (renderContext is null)
{
throw new ArgumentNullException(nameof(renderContext), "Parameter cannot be null or empty.");
}
// test the visualTree
- if (visualTree == null)
+ if (visualTree is null)
{
throw new ArgumentNullException(nameof(visualTree), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/WWW/Blog/Post/PostId/Edit.cs b/src/WebExpress.WebCore.Test/WWW/Blog/Post/PostId/Edit.cs
index 67384d7..69bf174 100644
--- a/src/WebExpress.WebCore.Test/WWW/Blog/Post/PostId/Edit.cs
+++ b/src/WebExpress.WebCore.Test/WWW/Blog/Post/PostId/Edit.cs
@@ -28,7 +28,7 @@ public Edit(IPageContext pageContext)
PageContext = pageContext;
// test the injection
- if (pageContext == null)
+ if (pageContext is null)
{
throw new ArgumentNullException(nameof(pageContext), "Parameter cannot be null or empty.");
}
@@ -42,7 +42,7 @@ public Edit(IPageContext pageContext)
public void Process(IRenderContext renderContext, VisualTree visualTree)
{
// test the context
- if (renderContext == null)
+ if (renderContext is null)
{
throw new ArgumentNullException(nameof(renderContext), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/WWW/Blog/Post/PostId/Index.cs b/src/WebExpress.WebCore.Test/WWW/Blog/Post/PostId/Index.cs
index 130a23d..40123bb 100644
--- a/src/WebExpress.WebCore.Test/WWW/Blog/Post/PostId/Index.cs
+++ b/src/WebExpress.WebCore.Test/WWW/Blog/Post/PostId/Index.cs
@@ -7,7 +7,7 @@ namespace WebExpress.WebCore.Test.WWW.Blog.Post.PostId
/// A dummy class for testing purposes.
///
[Title("webindex:index.label")]
- [SegmentGuid("segment")]
+ [SegmentGuid()]
public sealed class Index : IPage
{
///
@@ -29,7 +29,7 @@ public Index(IPageContext pageContext)
PageContext = pageContext;
// test the injection
- if (pageContext == null)
+ if (pageContext is null)
{
throw new ArgumentNullException(nameof(pageContext), "Parameter cannot be null or empty.");
}
@@ -43,7 +43,7 @@ public Index(IPageContext pageContext)
public void Process(IRenderContext renderContext, VisualTree visualTree)
{
// test the context
- if (renderContext == null)
+ if (renderContext is null)
{
throw new ArgumentNullException(nameof(renderContext), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/WWW/Contact.cs b/src/WebExpress.WebCore.Test/WWW/Contact.cs
index 3697d8e..132ca95 100644
--- a/src/WebExpress.WebCore.Test/WWW/Contact.cs
+++ b/src/WebExpress.WebCore.Test/WWW/Contact.cs
@@ -16,7 +16,7 @@ public sealed class Contact : Page
private Contact(IPageContext pageContext)
{
// test the injection
- if (pageContext == null)
+ if (pageContext is null)
{
throw new ArgumentNullException(nameof(pageContext), "Parameter cannot be null or empty.");
}
@@ -30,13 +30,13 @@ private Contact(IPageContext pageContext)
public override void Process(IRenderContext renderContext, TestVisualTree visualTree)
{
// test the context
- if (renderContext == null)
+ if (renderContext is null)
{
throw new ArgumentNullException(nameof(renderContext), "Parameter cannot be null or empty.");
}
// test the visualTree
- if (visualTree == null)
+ if (visualTree is null)
{
throw new ArgumentNullException(nameof(visualTree), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/WWW/Index.cs b/src/WebExpress.WebCore.Test/WWW/Index.cs
index cfc2e40..465d0a5 100644
--- a/src/WebExpress.WebCore.Test/WWW/Index.cs
+++ b/src/WebExpress.WebCore.Test/WWW/Index.cs
@@ -28,7 +28,7 @@ public Index(IPageContext pageContext)
PageContext = pageContext;
// test the injection
- if (pageContext == null)
+ if (pageContext is null)
{
throw new ArgumentNullException(nameof(pageContext), "Parameter cannot be null or empty.");
}
@@ -42,7 +42,7 @@ public Index(IPageContext pageContext)
public void Process(IRenderContext renderContext, VisualTree visualTree)
{
// test the context
- if (renderContext == null)
+ if (renderContext is null)
{
throw new ArgumentNullException(nameof(renderContext), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/WWW/Products/Details/Index.cs b/src/WebExpress.WebCore.Test/WWW/Products/Details/Index.cs
index edba4ad..85bd346 100644
--- a/src/WebExpress.WebCore.Test/WWW/Products/Details/Index.cs
+++ b/src/WebExpress.WebCore.Test/WWW/Products/Details/Index.cs
@@ -7,7 +7,7 @@ namespace WebExpress.WebCore.Test.WWW.Products.Details
/// A dummy class for testing purposes.
///
[Title("webindex:index.label")]
- [SegmentGuid("")]
+ [SegmentGuid()]
public sealed class Index : IPage
{
///
@@ -29,7 +29,7 @@ public Index(IPageContext pageContext)
PageContext = pageContext;
// test the injection
- if (pageContext == null)
+ if (pageContext is null)
{
throw new ArgumentNullException(nameof(pageContext), "Parameter cannot be null or empty.");
}
@@ -43,7 +43,7 @@ public Index(IPageContext pageContext)
public void Process(IRenderContext renderContext, VisualTree visualTree)
{
// test the context
- if (renderContext == null)
+ if (renderContext is null)
{
throw new ArgumentNullException(nameof(renderContext), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/WWW/Products/Index.cs b/src/WebExpress.WebCore.Test/WWW/Products/Index.cs
index 4349317..e5e0d65 100644
--- a/src/WebExpress.WebCore.Test/WWW/Products/Index.cs
+++ b/src/WebExpress.WebCore.Test/WWW/Products/Index.cs
@@ -6,6 +6,7 @@ namespace WebExpress.WebCore.Test.WWW.Products
///
/// A dummy class for testing purposes.
///
+ [SegmentHidden]
[Title("webindex:index.label")]
public sealed class Index : IPage
{
@@ -28,7 +29,7 @@ public Index(IPageContext pageContext)
PageContext = pageContext;
// test the injection
- if (pageContext == null)
+ if (pageContext is null)
{
throw new ArgumentNullException(nameof(pageContext), "Parameter cannot be null or empty.");
}
@@ -42,7 +43,7 @@ public Index(IPageContext pageContext)
public void Process(IRenderContext renderContext, VisualTree visualTree)
{
// test the context
- if (renderContext == null)
+ if (renderContext is null)
{
throw new ArgumentNullException(nameof(renderContext), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/WWW/Products/List.cs b/src/WebExpress.WebCore.Test/WWW/Products/List.cs
index 089f34e..9ef0163 100644
--- a/src/WebExpress.WebCore.Test/WWW/Products/List.cs
+++ b/src/WebExpress.WebCore.Test/WWW/Products/List.cs
@@ -28,7 +28,7 @@ public List(IPageContext pageContext)
PageContext = pageContext;
// test the injection
- if (pageContext == null)
+ if (pageContext is null)
{
throw new ArgumentNullException(nameof(pageContext), "Parameter cannot be null or empty.");
}
@@ -42,7 +42,7 @@ public List(IPageContext pageContext)
public void Process(IRenderContext renderContext, VisualTree visualTree)
{
// test the context
- if (renderContext == null)
+ if (renderContext is null)
{
throw new ArgumentNullException(nameof(renderContext), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/WWW/Resources/TestResourceA.cs b/src/WebExpress.WebCore.Test/WWW/Resources/TestResourceA.cs
index 4f65bf6..50f6685 100644
--- a/src/WebExpress.WebCore.Test/WWW/Resources/TestResourceA.cs
+++ b/src/WebExpress.WebCore.Test/WWW/Resources/TestResourceA.cs
@@ -15,7 +15,7 @@ public sealed class TestResourceA : IResource
public TestResourceA(IResourceContext resourceContext)
{
// test the injection
- if (resourceContext == null)
+ if (resourceContext is null)
{
throw new ArgumentNullException(nameof(resourceContext), "Parameter cannot be null or empty.");
}
@@ -26,10 +26,10 @@ public TestResourceA(IResourceContext resourceContext)
///
/// The request.
/// The processed response.
- public Response Process(Request request)
+ public IResponse Process(IRequest request)
{
// test the request
- if (request == null)
+ if (request is null)
{
throw new ArgumentNullException(nameof(request), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/WWW/Resources/TestResourceB.cs b/src/WebExpress.WebCore.Test/WWW/Resources/TestResourceB.cs
index ab0c2b4..e2d5ac8 100644
--- a/src/WebExpress.WebCore.Test/WWW/Resources/TestResourceB.cs
+++ b/src/WebExpress.WebCore.Test/WWW/Resources/TestResourceB.cs
@@ -20,10 +20,10 @@ public TestResourceB()
///
/// The request.
/// The processed response.
- public Response Process(Request request)
+ public IResponse Process(IRequest request)
{
// test the request
- if (request == null)
+ if (request is null)
{
throw new ArgumentNullException(nameof(request), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/WWW/Resources/TestResourceC.cs b/src/WebExpress.WebCore.Test/WWW/Resources/TestResourceC.cs
index 538e866..71990fd 100644
--- a/src/WebExpress.WebCore.Test/WWW/Resources/TestResourceC.cs
+++ b/src/WebExpress.WebCore.Test/WWW/Resources/TestResourceC.cs
@@ -16,13 +16,13 @@ public sealed class TestResourceC : IResource
public TestResourceC(IResourceManager resourceManager, IResourceContext resourceContext)
{
// test the injection
- if (resourceManager == null)
+ if (resourceManager is null)
{
throw new ArgumentNullException(nameof(resourceManager), "Parameter cannot be null or empty.");
}
// test the injection
- if (resourceContext == null)
+ if (resourceContext is null)
{
throw new ArgumentNullException(nameof(resourceContext), "Parameter cannot be null or empty.");
}
@@ -33,10 +33,10 @@ public TestResourceC(IResourceManager resourceManager, IResourceContext resource
///
/// The request.
/// The processed response.
- public Response Process(Request request)
+ public IResponse Process(IRequest request)
{
// test the request
- if (request == null)
+ if (request is null)
{
throw new ArgumentNullException(nameof(request), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/WWW/Resources/TestResourceD.cs b/src/WebExpress.WebCore.Test/WWW/Resources/TestResourceD.cs
index 7cc397c..001a328 100644
--- a/src/WebExpress.WebCore.Test/WWW/Resources/TestResourceD.cs
+++ b/src/WebExpress.WebCore.Test/WWW/Resources/TestResourceD.cs
@@ -16,13 +16,13 @@ public sealed class TestResourceD : IResource
public TestResourceD(IResourceContext resourceContext, IResourceManager resourceManager)
{
// test the injection
- if (resourceManager == null)
+ if (resourceManager is null)
{
throw new ArgumentNullException(nameof(resourceManager), "Parameter cannot be null or empty.");
}
// test the injection
- if (resourceContext == null)
+ if (resourceContext is null)
{
throw new ArgumentNullException(nameof(resourceContext), "Parameter cannot be null or empty.");
}
@@ -33,10 +33,10 @@ public TestResourceD(IResourceContext resourceContext, IResourceManager resource
///
/// The request.
/// The processed response.
- public Response Process(Request request)
+ public IResponse Process(IRequest request)
{
// test the request
- if (request == null)
+ if (request is null)
{
throw new ArgumentNullException(nameof(request), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/WWW/Settings/TestSettingPageA.cs b/src/WebExpress.WebCore.Test/WWW/Settings/TestSettingPageA.cs
index 81340d0..e3e12a8 100644
--- a/src/WebExpress.WebCore.Test/WWW/Settings/TestSettingPageA.cs
+++ b/src/WebExpress.WebCore.Test/WWW/Settings/TestSettingPageA.cs
@@ -26,7 +26,7 @@ public TestSettingPageA(ISettingPageContext pageContext)
PageContext = pageContext;
// test the injection
- if (pageContext == null)
+ if (pageContext is null)
{
throw new ArgumentNullException(nameof(pageContext), "Parameter cannot be null or empty.");
}
@@ -40,7 +40,7 @@ public TestSettingPageA(ISettingPageContext pageContext)
public void Process(IRenderContext renderContext, VisualTree visualTree)
{
// test the context
- if (renderContext == null)
+ if (renderContext is null)
{
throw new ArgumentNullException(nameof(renderContext), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/WWW/Settings/TestSettingPageB.cs b/src/WebExpress.WebCore.Test/WWW/Settings/TestSettingPageB.cs
index 4530e2a..81a9582 100644
--- a/src/WebExpress.WebCore.Test/WWW/Settings/TestSettingPageB.cs
+++ b/src/WebExpress.WebCore.Test/WWW/Settings/TestSettingPageB.cs
@@ -26,7 +26,7 @@ public TestSettingPageB(ISettingPageContext pageContext)
PageContext = pageContext;
// test the injection
- if (pageContext == null)
+ if (pageContext is null)
{
throw new ArgumentNullException(nameof(pageContext), "Parameter cannot be null or empty.");
}
@@ -40,7 +40,7 @@ public TestSettingPageB(ISettingPageContext pageContext)
public void Process(IRenderContext renderContext, VisualTree visualTree)
{
// test the context
- if (renderContext == null)
+ if (renderContext is null)
{
throw new ArgumentNullException(nameof(renderContext), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/WWW/Settings/TestSettingPageC.cs b/src/WebExpress.WebCore.Test/WWW/Settings/TestSettingPageC.cs
index 3f29a23..0e54eb0 100644
--- a/src/WebExpress.WebCore.Test/WWW/Settings/TestSettingPageC.cs
+++ b/src/WebExpress.WebCore.Test/WWW/Settings/TestSettingPageC.cs
@@ -24,7 +24,7 @@ public TestSettingPageC(ISettingPageContext pageContext)
PageContext = pageContext;
// test the injection
- if (pageContext == null)
+ if (pageContext is null)
{
throw new ArgumentNullException(nameof(pageContext), "Parameter cannot be null or empty.");
}
@@ -38,7 +38,7 @@ public TestSettingPageC(ISettingPageContext pageContext)
public void Process(IRenderContext renderContext, VisualTree visualTree)
{
// test the context
- if (renderContext == null)
+ if (renderContext is null)
{
throw new ArgumentNullException(nameof(renderContext), "Parameter cannot be null or empty.");
}
diff --git a/src/WebExpress.WebCore.Test/WebExpress.WebCore.Test.csproj b/src/WebExpress.WebCore.Test/WebExpress.WebCore.Test.csproj
index a2ce933..ee13ee0 100644
--- a/src/WebExpress.WebCore.Test/WebExpress.WebCore.Test.csproj
+++ b/src/WebExpress.WebCore.Test/WebExpress.WebCore.Test.csproj
@@ -1,7 +1,7 @@
- net9.0
+ net10.0
enable
disable
@@ -41,9 +41,9 @@
-
+
-
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
diff --git a/src/WebExpress.WebCore.Test/Uri/UnitTestUri.cs b/src/WebExpress.WebCore.Test/WebUri/UnitTestUri.cs
similarity index 52%
rename from src/WebExpress.WebCore.Test/Uri/UnitTestUri.cs
rename to src/WebExpress.WebCore.Test/WebUri/UnitTestUri.cs
index cb5e36a..24cd78a 100644
--- a/src/WebExpress.WebCore.Test/Uri/UnitTestUri.cs
+++ b/src/WebExpress.WebCore.Test/WebUri/UnitTestUri.cs
@@ -1,7 +1,9 @@
-using WebExpress.WebCore.WebEndpoint;
+using WebExpress.WebCore.Test.Fixture;
+using WebExpress.WebCore.Test.WWW;
+using WebExpress.WebCore.WebEndpoint;
using WebExpress.WebCore.WebUri;
-namespace WebExpress.WebCore.Test.Uri
+namespace WebExpress.WebCore.Test.WebUri
{
///
/// Tests an uri.
@@ -23,15 +25,16 @@ public class UnitTestUri
[InlineData(UriScheme.Http, "example.com", "user", "80", "/abc", "a=1&b=2", "fragment", "http://user@example.com/abc?a=1&b=2#fragment")]
public void UriAbsolute(UriScheme scheme, string authority, string user, string port, string path, string query, string fragment, string expected)
{
- // preconditions
- var uriUser = user != null ? user + "@" : "";
- var uriPort = port != null ? ":" + port : null;
- var uriQuery = query != null ? "?" + query : "";
- var uriFragment = fragment != null ? "#" + fragment : null;
+ // arrange
+ var uriUser = user is not null ? user + "@" : "";
+ var uriPort = port is not null ? ":" + port : null;
+ var uriQuery = query is not null ? "?" + query : "";
+ var uriFragment = fragment is not null ? "#" + fragment : null;
- // test execution
+ // act
var uri = new UriEndpoint($"{scheme}://{uriUser}{authority}{uriPort}{path}{uriQuery}{uriFragment}");
+ // validation
Assert.Equal(expected, uri.ToString());
Assert.Equal(scheme, uri.Scheme);
Assert.Equal(authority, uri.Authority.Host);
@@ -60,13 +63,14 @@ public void UriAbsolute(UriScheme scheme, string authority, string user, string
[InlineData("/assets/img/example.svg", null, null, "/assets/img/example.svg")]
public void UriRelative(string path, string query, string fragment, string expected)
{
- // preconditions
- var uriQuery = query != null ? "?" + query : "";
- var uriFragment = fragment != null ? "#" + fragment : null;
+ // arrange
+ var uriQuery = query is not null ? "?" + query : "";
+ var uriFragment = fragment is not null ? "#" + fragment : null;
- // test execution
+ // act
var uri = new UriEndpoint($"{path}{uriQuery}{uriFragment}");
+ // validation
Assert.Equal(expected, uri.ToString());
Assert.Equal(path, !string.IsNullOrWhiteSpace(path)
? "/" + string.Join("/", uri.PathSegments.Skip(1))
@@ -85,16 +89,36 @@ public void UriRelative(string path, string query, string fragment, string expec
[InlineData("/a/b/c", "/d/e/f", "/a/b/c/d/e/f", 7)]
public void Concat(string path, string segment, string expected, int count)
{
- // preconditions
+ // arrange
var uri = new UriEndpoint(path);
- // test execution
+ // act
var concat = uri.Concat(segment);
+ // validation
Assert.Equal(expected, concat.ToString());
Assert.Equal(count, concat.PathSegments.Count());
}
+ ///
+ /// Test the concat method.
+ ///
+ [Theory]
+ [InlineData(null, null, "/")]
+ [InlineData("a", null, "/?a=")]
+ [InlineData("b", "x", "/?b=x")]
+ public void ConcatQuery(string key, string value, string expected)
+ {
+ // arrange
+ var uri = new UriEndpoint();
+
+ // act
+ var concat = uri.Concat(key is not null ? new UriQuery(key, value) : null);
+
+ // validation
+ Assert.Equal(expected, concat.ToString());
+ }
+
///
/// Test the skip method.
///
@@ -107,12 +131,13 @@ public void Concat(string path, string segment, string expected, int count)
[InlineData("/a/b/c", 5, null)]
public void Skip(string path, int skipCount, string expected)
{
- // preconditions
+ // arrange
var uri = new UriEndpoint(path);
- // test execution
+ // act
var skip = uri.Skip(skipCount);
+ // validation
Assert.Equal(expected, skip?.ToString());
}
@@ -133,12 +158,36 @@ public void Skip(string path, int skipCount, string expected)
[InlineData("/a/b/c", -5, null)]
public void Take(string path, int takeCount, string expected)
{
- // preconditions
+ // arrange
var uri = new UriEndpoint(path);
- // test execution
+ // act
var take = uri.Take(takeCount);
+ // validation
+ Assert.Equal(expected, take?.ToString());
+ }
+
+ ///
+ /// Test the take last method.
+ ///
+ [Theory]
+ [InlineData("/a/b/c", 0, "/a/b/c")]
+ [InlineData("/a/b/c", 1, "/c")]
+ [InlineData("/a/b/c", 2, "/b/c")]
+ [InlineData("/a/b/c", 3, "/a/b/c")]
+ [InlineData("/a/b/c", 4, "/a/b/c")]
+ [InlineData("/a/b/c", 5, "/a/b/c")]
+ [InlineData("/a/b/c", -5, "/a/b/c")]
+ public void TakeLast(string path, int takeCount, string expected)
+ {
+ // arrange
+ var uri = new UriEndpoint(path);
+
+ // act
+ var take = uri.TakeLast(takeCount);
+
+ // validation
Assert.Equal(expected, take?.ToString());
}
@@ -152,7 +201,7 @@ public void Take(string path, int takeCount, string expected)
[InlineData("http://www.example.com/a/$guid/c", "/a/$guid/c", "http://www.example.com/a/$guid/c")]
public void Merge(string uri, string route, string expected)
{
- // preconditions
+ // arrange
var random = Guid.NewGuid().ToString();
var uriEndpoint = new UriEndpoint(uri.Replace("$guid", random));
var routeEndpoint = new RouteEndpoint
@@ -160,14 +209,15 @@ public void Merge(string uri, string route, string expected)
[.. route.Split('/').Select
(
x => (IUriPathSegment)(x == "$guid"
- ? new UriPathSegmentVariableGuid("guid") { Value = random }
+ ? new UriPathSegmentVariableGuid("guid") { Value = random }
: new UriPathSegmentConstant(x))
)]
);
- // test execution
+ // act
var resourceUri = new UriEndpoint(uriEndpoint, routeEndpoint.PathSegments);
+ // validation
Assert.Equal(expected.Replace("$guid", random), resourceUri?.ToString());
}
@@ -179,17 +229,19 @@ [.. route.Split('/').Select
[InlineData("http://user@example.com/a/b/c/x/y/z", "http://user@example.com/a/b/c", "http://user@example.com/a/b/c")]
public void BasePath(string uri, string baseUri, string expected)
{
+ // act
var resourceUri = new UriEndpoint(uri)
{
BasePath = new UriEndpoint(baseUri)
};
+ // validation
Assert.Equal(uri, resourceUri.ToString());
Assert.Equal(expected, resourceUri.BasePath.ToString());
}
///
- /// Test the setfragment method.
+ /// Test the SetFragment method.
///
[Theory]
[InlineData("http://user@example.com/x", null, "http://user@example.com/x")]
@@ -198,16 +250,145 @@ public void BasePath(string uri, string baseUri, string expected)
[InlineData("http://user@example.com/a/b/c", "myfragment", "http://user@example.com/a/b/c#myfragment")]
public void SetFragment(string uri, string fragment, string expected)
{
- // preconditions
+ // arrange
var resourceUri = (IUri)new UriEndpoint(uri)
{
};
- // test execution
+ // act
resourceUri = resourceUri.SetFragment(fragment);
// validation
Assert.Equal(expected, resourceUri.ToString());
}
+
+ ///
+ /// Test the GetDisplayText method.
+ ///
+ [Theory]
+ [InlineData(typeof(TestApplicationA), typeof(WWW.Index), null)]
+ [InlineData(typeof(TestApplicationA), typeof(About), null)]
+ [InlineData(typeof(TestApplicationA), typeof(Contact), null)]
+ [InlineData(typeof(TestApplicationB), typeof(WWW.Index), null)]
+ [InlineData(typeof(TestApplicationB), typeof(About), null)]
+ [InlineData(typeof(TestApplicationB), typeof(Contact), null)]
+ [InlineData(typeof(TestApplicationC), typeof(WWW.Index), null)]
+ [InlineData(typeof(TestApplicationC), typeof(About), null)]
+ [InlineData(typeof(TestApplicationC), typeof(Contact), null)]
+ public void GetDisplayText(Type applicationType, Type resourceType, string expected)
+ {
+ // arrange
+ var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
+ var application = componentHub.ApplicationManager.GetApplications(applicationType)?.FirstOrDefault();
+ componentHub.SitemapManager.Refresh();
+ var page = componentHub.PageManager.GetPages(resourceType, application)?.FirstOrDefault();
+ var endpoint = componentHub.SitemapManager.GetEndpoint(page.Route.ToUri());
+ var renderContext = UnitTestFixture.CrerateRenderContextMock(application);
+
+ // act
+ var display = endpoint.Route.ToUri().GetDisplayText(renderContext);
+
+ // validation
+ Assert.Equal(expected, display);
+ }
+
+ ///
+ /// Tests the BindParameters method to verify that parameters are correctly
+ /// bound to the URI endpoint.
+ ///
+ [Fact]
+ public void BindParametersSingle()
+ {
+ // arrange
+ var pathSegments = new IUriPathSegment[]
+ {
+ new UriPathSegmentConstant("a"),
+ new UriPathSegmentVariableGuid("testparametera"),
+ new UriPathSegmentConstant("b")
+ };
+
+ var uri = new UriEndpoint(pathSegments);
+ var parameter = new TestParameterA()
+ {
+ Value = "CFABEA8C-4223-4E17-AB31-C8FA4454B745"
+ };
+
+ // act
+ var bind = uri.BindParameters(parameter);
+
+ // validation
+ Assert.Equal("/a/${testparametera}/b", uri.ToString());
+ Assert.Equal("/a/CFABEA8C-4223-4E17-AB31-C8FA4454B745/b", bind.ToString());
+ }
+
+ ///
+ /// Tests the BindParameters method to verify that parameters are correctly
+ /// bound to the URI endpoint.
+ ///
+ [Fact]
+ public void BindParametersMultible()
+ {
+ // arrange
+ var pathSegments = new IUriPathSegment[]
+ {
+ new UriPathSegmentConstant("a"),
+ new UriPathSegmentVariableInt(),
+ new UriPathSegmentConstant("b"),
+ new UriPathSegmentVariableInt()
+ };
+
+ var uri = new UriEndpoint(pathSegments);
+ var parameter1 = new TestParameterA()
+ {
+ Value = "10"
+ };
+
+ var parameter2 = new TestParameterB()
+ {
+ Value = "20"
+ };
+
+ // act
+ var bind = uri.BindParameters(parameter1, parameter2);
+
+ // validation
+ Assert.Equal("/a/${testparametera}/b/${testparameterb}", uri.ToString());
+ Assert.Equal("/a/10/b/20", bind.ToString());
+ }
+
+ ///
+ /// Tests the BindParameters method to verify that parameters are correctly
+ /// bound to the URI endpoint.
+ ///
+ [Fact]
+ public void BindParametersQuery()
+ {
+ // arrange
+ var pathSegments = new IUriPathSegment[]
+ {
+ new UriPathSegmentConstant("a"),
+ new UriPathSegmentVariableInt(),
+ new UriPathSegmentConstant("b")
+ };
+
+ var uri = new UriEndpoint(pathSegments)
+ .Add(new UriQuery());
+ var parameter1 = new TestParameterA()
+ {
+ Value = "10"
+ };
+
+ var parameter2 = new TestParameterB()
+ {
+ Value = "20"
+ };
+
+ // act
+ var bind = uri.BindParameters(parameter1, parameter2);
+
+ // validation
+ Assert.Equal("/a/${testparametera}/b?testparameterb=", uri.ToString());
+ Assert.Equal("/a/10/b?testparameterb=20", bind.ToString());
+ }
}
}
diff --git a/src/WebExpress.WebCore/ArgumentParser.cs b/src/WebExpress.WebCore/ArgumentParser.cs
index 8b473f7..9ba11f7 100644
--- a/src/WebExpress.WebCore/ArgumentParser.cs
+++ b/src/WebExpress.WebCore/ArgumentParser.cs
@@ -78,7 +78,7 @@ where x.FullName.Equals(key[1..], StringComparison.OrdinalIgnoreCase) ||
x.ShortName.Equals(key[1..], StringComparison.OrdinalIgnoreCase)
select x).FirstOrDefault();
- if (command != null)
+ if (command is not null)
{
argsDict.Add(command.FullName.ToLower(), value.Trim());
}
@@ -100,7 +100,7 @@ where x.FullName.Equals(key[1..], StringComparison.OrdinalIgnoreCase) ||
x.ShortName.Equals(key[1..], StringComparison.OrdinalIgnoreCase)
select x).FirstOrDefault();
- if (command != null)
+ if (command is not null)
{
argsDict.Add(command.FullName.ToLower(), value.Trim());
}
diff --git a/src/WebExpress.WebCore/HttpServer.cs b/src/WebExpress.WebCore/HttpServer.cs
index b91e0f5..e5fbcf5 100644
--- a/src/WebExpress.WebCore/HttpServer.cs
+++ b/src/WebExpress.WebCore/HttpServer.cs
@@ -1,4 +1,4 @@
-using Microsoft.AspNetCore.Hosting;
+using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Server.Kestrel.Core;
@@ -7,21 +7,25 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
+using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Net.Sockets;
+using System.Reflection;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.Threading.Tasks;
using WebExpress.WebCore.Config;
using WebExpress.WebCore.Internationalization;
using WebExpress.WebCore.WebEndpoint;
-using WebExpress.WebCore.WebHtml;
using WebExpress.WebCore.WebLog;
using WebExpress.WebCore.WebMessage;
+using WebExpress.WebCore.WebParameter;
using WebExpress.WebCore.WebSitemap;
+using WebExpress.WebCore.WebSocket;
+using WebExpress.WebCore.WebStatusPage;
using WebExpress.WebCore.WebUri;
namespace WebExpress.WebCore
@@ -29,7 +33,7 @@ namespace WebExpress.WebCore
///
/// The web server for processing http requests (see RFC 2616). The web server uses Kestrel internally.
///
- public class HttpServer : IHost, IHttpApplication
+ public class HttpServer : IHost, IHttpApplication
{
///
/// Event is triggered after the web server is started.
@@ -44,10 +48,10 @@ public class HttpServer : IHost, IHttpApplication
///
/// Server thread termination.
///
- private CancellationToken ServerToken { get; } = new CancellationToken();
+ private CancellationTokenSource ServerTokenSource { get; } = new CancellationTokenSource();
///
- /// Returns or sets the configuration
+ /// Returns or sets the configuration.
///
public HttpServerConfig Config { get; set; }
@@ -71,10 +75,25 @@ public class HttpServer : IHost, IHttpApplication
///
public long RequestNumber { get; private set; }
+ ///
+ /// Returns the statistics history.
+ ///
+ public static List Statistics { get; } = [];
+
+ ///
+ /// Synchronization object for statistics.
+ ///
+ private static readonly Lock _statLock = new();
+
+ // Variables for CPU usage calculation
+ private static DateTime _lastCpuTime = DateTime.UtcNow;
+ private static TimeSpan _lastProcessorTime = Process.GetCurrentProcess().TotalProcessorTime;
+ private static readonly Process _currentProcess = Process.GetCurrentProcess();
+
///
/// Initializes a new instance of the class.
///
- /// Der Serverkontext.
+ /// The server context.
public HttpServer(HttpServerContext context)
{
HttpServerContext = new HttpServerContext
@@ -109,7 +128,10 @@ public void Start()
}
var logger = new LogFactory();
- var transportOptions = new OptionsWrapper(new SocketTransportOptions());
+ var transportOptions = new OptionsWrapper
+ (
+ new SocketTransportOptions()
+ );
var transport = new SocketTransportFactory(transportOptions, logger);
var serviceCollection = new ServiceCollection();
@@ -119,10 +141,13 @@ public void Start()
x.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
x.AddProvider(logger);
});
- serviceCollection.AddHttpLogging(x =>
- {
- x.LoggingFields = Microsoft.AspNetCore.HttpLogging.HttpLoggingFields.All;
- });
+ serviceCollection.AddHttpLogging
+ (
+ x =>
+ {
+ x.LoggingFields = Microsoft.AspNetCore.HttpLogging.HttpLoggingFields.All;
+ }
+ );
var serverOptions = new OptionsWrapper(new KestrelServerOptions()
{
@@ -130,11 +155,14 @@ public void Start()
AllowResponseHeaderCompression = true,
AddServerHeader = true,
ApplicationServices = serviceCollection.BuildServiceProvider()
-
});
- serverOptions.Value.Limits.MaxConcurrentConnections = Config?.Limit?.ConnectionLimit > 0 ? Config?.Limit?.ConnectionLimit : serverOptions.Value.Limits.MaxConcurrentConnections;
- serverOptions.Value.Limits.MaxRequestBodySize = Config?.Limit?.UploadLimit > 0 ? Config?.Limit?.UploadLimit : serverOptions.Value.Limits.MaxRequestBodySize;
+ serverOptions.Value.Limits.MaxConcurrentConnections = Config?.Limit?.ConnectionLimit > 0
+ ? Config?.Limit?.ConnectionLimit
+ : serverOptions.Value.Limits.MaxConcurrentConnections;
+ serverOptions.Value.Limits.MaxRequestBodySize = Config?.Limit?.UploadLimit > 0
+ ? Config?.Limit?.UploadLimit
+ : serverOptions.Value.Limits.MaxRequestBodySize;
foreach (var endpoint in Config.Endpoints)
{
@@ -142,10 +170,13 @@ public void Start()
}
Kestrel = new KestrelServer(serverOptions, transport, logger);
+ Kestrel.StartAsync(this, ServerTokenSource.Token);
- Kestrel.StartAsync(this, ServerToken);
-
- HttpServerContext.Log.Info(message: I18N.Translate("webexpress.webcore:httpserver.start"), args: [ExecutionTime.ToShortDateString(), ExecutionTime.ToLongTimeString()]);
+ HttpServerContext.Log.Info(message: I18N.Translate
+ (
+ "webexpress.webcore:httpserver.start"),
+ args: [ExecutionTime.ToShortDateString(), ExecutionTime.ToLongTimeString()]
+ );
Started?.Invoke(this, new EventArgs());
}
@@ -176,10 +207,17 @@ private void AddEndpoint(OptionsWrapper serverOptions, End
switch (uri.Scheme)
{
- case "HTTPS": { AddEndpoint(serverOptions, ep, endPoint.PfxFile, endPoint.Password); break; }
- default: { AddEndpoint(serverOptions, ep); break; }
+ case "HTTPS":
+ {
+ AddEndpoint(serverOptions, ep, endPoint.PfxFile, endPoint.Password);
+ break;
+ }
+ default:
+ {
+ AddEndpoint(serverOptions, ep);
+ break;
+ }
}
-
}
}
catch (Exception ex)
@@ -197,7 +235,6 @@ private void AddEndpoint(OptionsWrapper serverOptions, End
private void AddEndpoint(OptionsWrapper serverOptions, IPEndPoint endPoint)
{
serverOptions.Value.Listen(endPoint);
-
HttpServerContext.Log.Info(message: I18N.Translate("webexpress.webcore:httpserver.listen"), args: endPoint.ToString());
}
@@ -213,7 +250,6 @@ private void AddEndpoint(OptionsWrapper serverOptions, IPE
serverOptions.Value.Listen(endPoint, configure =>
{
var cert = X509CertificateLoader.LoadPkcs12FromFile(pfxFile, password, X509KeyStorageFlags.DefaultKeySet);
-
configure.UseHttps(cert);
});
@@ -221,27 +257,26 @@ private void AddEndpoint(OptionsWrapper serverOptions, IPE
}
///
- /// Stops the HTTP(S) server
+ /// Stops the HTTP(S) server.
///
public void Stop()
{
- // End running threads
- Kestrel.StopAsync(ServerToken);
+ // signal cancellation and stop server
+ ServerTokenSource.Cancel();
+ Kestrel.StopAsync(ServerTokenSource.Token);
}
///
- /// Handles an incoming request
- /// Concurrent execution
+ /// Handles an incoming request.
///
/// The context of the web request.
+ /// The previously resolved search result for the request.
/// The response to be sent back to the caller.
- private Response HandleClient(HttpContext context)
+ private IResponse HandleClient(IHttpContext context, SearchResult searchResult)
{
var stopwatch = Stopwatch.StartNew();
var request = context.Request;
- var response = default(Response);
- var culture = request.Culture;
- var uri = request?.Uri;
+ var response = default(IResponse);
HttpServerContext.Log.Debug(message: I18N.Translate("webexpress.webcore:httpserver.connected"), args: context.RemoteEndPoint);
HttpServerContext.Log.Info(I18N.Translate
@@ -252,85 +287,83 @@ private Response HandleClient(HttpContext context)
$"{request?.Method} {request?.Uri} {request?.Protocoll}"
));
- // search page in sitemap
- var searchResult = WebEx.ComponentHub.SitemapManager.SearchResource(context.Uri, new SearchContext()
- {
- Culture = culture,
- HttpContext = context,
- HttpServerContext = HttpServerContext
- });
+ var resourceUri = new UriEndpoint(request.Uri, searchResult.Uri.PathSegments);
+ request.Uri = resourceUri;
- if (searchResult != null)
+ try
{
- var resourceUri = new UriEndpoint(request.Uri, searchResult.Uri.PathSegments);
- request.Uri = resourceUri;
+ // execute resource
+ request.AddParameter(searchResult.Uri.Parameters.Select(x => new Parameter(x.Key, x.Value, ParameterScope.Url)));
- try
+ if (searchResult.EndpointContext != null)
{
- // execute resource
- request.AddParameter(searchResult.Uri.Parameters.Select(x => new Parameter(x.Key, x.Value, ParameterScope.Url)));
+ response = WebEx.ComponentHub.EndpointManager.HandleRequest(request, searchResult.EndpointContext);
- if (searchResult.EndpointContext != null)
+ if (response is ResponseNotFound)
{
- response = WebEx.ComponentHub.EndpointManager.HandleRequest(request, searchResult.EndpointContext);
-
- if (response is ResponseNotFound)
- {
- response = CreateStatusPage
- (
- string.Empty,
- request,
- searchResult
- );
- }
-
- if
- (
- !response.Header.Cookies.Where(x => x.Name.Equals("session")).Any() &&
- !request.Header.Cookies.Where(x => x.Name.Equals("session")).Any() &&
- request.Session != null
- )
- {
- var cookie = new Cookie("session", request.Session.Id.ToString()) { Expires = DateTime.MaxValue };
- response.Header.Cookies.Add(cookie);
- }
- }
- else
- {
- // Resource not found
response = CreateStatusPage
(
- "Resource not found",
+ string.Empty,
request,
searchResult
);
}
- }
- catch (RedirectException ex)
- {
- if (ex.Permanet)
- {
- response = new ResponseMovedPermanently(ex.Uri);
- }
- else
+
+ if
+ (
+ !response.Header.Cookies.Where(x => x.Name.Equals("session")).Any() &&
+ !request.Header.Cookies.Where(x => x.Name.Equals("session")).Any() &&
+ request.Session != null
+ )
{
- response = new ResponseMovedTemporarily(ex.Uri);
+ var cookie = new Cookie("session", request.Session.Id.ToString()) { Expires = DateTime.MaxValue };
+ response.Header.Cookies.Add(cookie);
}
}
- catch (BadRequestException ex)
+ else
{
- var message = $"Message
{ex.Message}
" +
- $"Source
{ex.Source}
" +
- $"StackTrace
{ex.StackTrace.Replace("\n", "
\n")}";
-
- response = CreateStatusPage
+ // resource not found
+ response = CreateStatusPage
(
- message,
+ "Resource not found",
request,
searchResult
);
}
- catch (Exception ex)
+ }
+ catch (RedirectException ex)
+ {
+ if (ex.Permanet)
+ {
+ response = new ResponseMovedPermanently(ex.Uri);
+ }
+ else
+ {
+ response = new ResponseMovedTemporarily(ex.Uri);
+ }
+ }
+ catch (BadRequestException ex)
+ {
+ var message = $"Message
{ex.Message}
" +
+ $"Source
{ex.Source}
" +
+ $"StackTrace
{ex.StackTrace.Replace("\n", "
\n")}";
+
+ response = CreateStatusPage
+ (
+ message,
+ request,
+ searchResult
+ );
+ }
+ catch (Exception ex)
+ {
+ if (ex is TargetInvocationException tie && tie.InnerException is RedirectException rex)
+ {
+ response = rex.Permanet
+ ? new ResponseMovedPermanently(rex.Uri)
+ : new ResponseMovedTemporarily(rex.Uri);
+ }
+ else
{
HttpServerContext.Log.Exception(ex);
@@ -347,14 +380,11 @@ private Response HandleClient(HttpContext context)
);
}
}
- else
- {
- // Resource not found
- response = CreateStatusPage("Resource not found", request);
- }
stopwatch.Stop();
+ UpdateStatistics(response, stopwatch.ElapsedMilliseconds);
+
HttpServerContext.Log.Info(I18N.Translate
(
"webexpress.webcore:httpserver.request.done",
@@ -368,91 +398,98 @@ private Response HandleClient(HttpContext context)
}
///
- /// Sends the response message
+ /// Updates the request statistics with ring buffer logic (max 24h).
///
- /// The context of the request
- /// The reply message
- /// Sending the message as a task, which is executed concurrently.
- private async Task SendResponseAsync(HttpContext context, Response response)
+ /// The response containing the status code.
+ /// The duration of the request in milliseconds.
+ private static void UpdateStatistics(IResponse response, long duration)
{
- try
- {
- var responseFeature = context.Features.Get();
- var responseBodyFeature = context.Features.Get();
+ var now = DateTime.Now;
+ var minute = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, 0);
+ var isError = response != null && response.Status >= 400;
- responseFeature.StatusCode = response.Status;
- responseFeature.ReasonPhrase = response.Reason;
- responseFeature.Headers.KeepAlive = "true";
+ // calculate memory usage in MB
+ var memUsage = _currentProcess.WorkingSet64 / (1024.0 * 1024.0);
- if (response.Header.Location != null)
- {
- responseFeature.Headers.Location = response.Header.Location;
- }
+ // calculate cpu usage
+ var currentCpuTime = _currentProcess.TotalProcessorTime;
+ var currentWallTime = DateTime.UtcNow;
+ var cpuUsedMs = (currentCpuTime - _lastProcessorTime).TotalMilliseconds;
+ var totalMsPassed = (currentWallTime - _lastCpuTime).TotalMilliseconds;
+ var cpuUsage = 0.0;
- if (!string.IsNullOrWhiteSpace(response.Header.CacheControl))
- {
- responseFeature.Headers.CacheControl = response.Header.CacheControl;
- }
+ if (totalMsPassed > 0)
+ {
+ cpuUsage = (cpuUsedMs / (totalMsPassed * Environment.ProcessorCount)) * 100.0;
+ }
- if (!string.IsNullOrWhiteSpace(response.Header.ContentType))
- {
- responseFeature.Headers.ContentType = response.Header.ContentType;
- }
+ // update pointers for next calculation
+ _lastProcessorTime = currentCpuTime;
+ _lastCpuTime = currentWallTime;
- if (response.Header.WWWAuthenticate)
+ lock (_statLock)
+ {
+ // remove entries older than 24 hours (1440 minutes)
+ while (Statistics.Count >= 1440)
{
- responseFeature.Headers.WWWAuthenticate = "Basic realm=\"Bereich\"";
+ Statistics.RemoveAt(0);
}
- if (response.Header.Cookies.Count != 0)
- {
- responseFeature.Headers.SetCookie = string.Join(" ", response.Header.Cookies);
- }
+ var current = Statistics.LastOrDefault();
- if (response?.Content is byte[] byteContent)
- {
- responseFeature.Headers.ContentLength = byteContent.Length;
- await responseBodyFeature.Stream.WriteAsync(byteContent);
- await responseBodyFeature.Stream.FlushAsync();
- }
- else if (response?.Content is string strContent)
+ if (current != null && current.Timestamp == minute)
{
- var content = context.Encoding.GetBytes(strContent);
+ current.Requests++;
+ if (isError)
+ {
+ current.Errors++;
+ }
+
+ // update min, max and total duration
+ if (duration < current.MinDuration)
+ {
+ current.MinDuration = duration;
+ }
+ if (duration > current.MaxDuration)
+ {
+ current.MaxDuration = duration;
+ }
+ current.TotalDuration += duration;
- responseFeature.Headers.ContentLength = content.Length;
- await responseBodyFeature.Stream.WriteAsync(content);
- await responseBodyFeature.Stream.FlushAsync();
+ // calculate moving average for system metrics within this minute
+ current.CpuUsage += (cpuUsage - current.CpuUsage) / current.Requests;
+ current.MemoryUsage += (memUsage - current.MemoryUsage) / current.Requests;
}
- else if (response?.Content is IHtmlNode htmlContent)
+ else
{
- var content = context.Encoding.GetBytes(htmlContent?.ToString());
-
- responseFeature.Headers.ContentLength = content.Length;
- await responseBodyFeature.Stream.WriteAsync(content);
- await responseBodyFeature.Stream.FlushAsync();
+ Statistics.Add(new HttpServerStatisticItem()
+ {
+ Timestamp = minute,
+ Requests = 1,
+ Errors = isError ? 1 : 0,
+ MinDuration = duration,
+ MaxDuration = duration,
+ TotalDuration = duration,
+ CpuUsage = cpuUsage,
+ MemoryUsage = memUsage
+ });
}
-
- responseBodyFeature.Stream.Close();
- }
- catch (Exception ex)
- {
- HttpServerContext.Log.Error(context.RemoteEndPoint + ": " + ex.Message);
}
}
///
- /// Creates a status page
+ /// Creates a status page.
///
/// The error message.
/// The request.
/// The plugin by searching the status page or null.
/// The response.
- private static Response CreateStatusPage(string message, Request request, SearchResult searchResult = null) where T : Response, new()
+ private static Response CreateStatusPage(string message, IRequest request, SearchResult searchResult = null) where T : Response, new()
{
var response = new T() as Response;
var statusPageManager = WebEx.ComponentHub.StatusPageManager;
var applicationManager = WebEx.ComponentHub.ApplicationManager;
- var route = new RouteEndpoint([.. request.Uri.PathSegments])?.ToString();
+ var route = new RouteEndpoint(request.Uri.PathSegments)?.ToString();
var applicationContext = applicationManager.Applications
.Where(x => route.StartsWith(x.Route.ToString()))
.FirstOrDefault();
@@ -491,48 +528,159 @@ private async Task SendResponseAsync(HttpContext context, Response response)
}
///
- /// Create an HttpContext with a collection of HTTP features.
+ /// Creates an appropriate IHttpContext instance (HttpContext or WebSocketContext)
+ /// based on feature detection.
///
- /// A collection of HTTP features to use to create the HttpContext.
- /// The HttpContext created.
- public HttpContext CreateContext(IFeatureCollection contextFeatures)
+ /// The feature collection of the request.
+ /// An IHttpContext instance for the request.
+ public IHttpContext CreateContext(IFeatureCollection contextFeatures)
{
try
{
+ var requestFeature = contextFeatures.Get();
+
+ // check if schema or upgrade header indicates websocket
+ if (IsWebSocketRequest(requestFeature))
+ {
+ // use WebSocketContext for websocket connections
+ return new HttpWebSocketContext(contextFeatures, HttpServerContext);
+ }
+
+ // use regular HttpContext for normal HTTP requests
return new HttpContext(contextFeatures, HttpServerContext);
}
catch (Exception ex)
{
+ // fall back to HttpExceptionContext on error
return new HttpExceptionContext(ex, contextFeatures);
}
}
///
/// Processes an http context asynchronously.
+ /// If the request is a websocket upgrade to a configured endpoint, handle
+ /// websocket lifecycle instead of request/response.
+ /// Handles missing sitemap endpoints directly here.
///
- /// The http context that the operation processes.
+ /// The http context that the operation processes.
/// Provides an asynchronous operation that handles the http context.
- public async Task ProcessRequestAsync(HttpContext context)
+ public async Task ProcessRequestAsync(IHttpContext httpContext)
{
- if (context is HttpExceptionContext exceptionContext)
+ var responseSender = new ResponseSender();
+
+ if (httpContext is HttpExceptionContext exceptionContext)
{
var message = "404" +
- $"Message
{exceptionContext.Exception.Message}
" +
- $"Source
{exceptionContext.Exception.Source}
" +
- $"StackTrace
{exceptionContext.Exception.StackTrace.Replace("\n", "
\n")}
" +
- $"InnerException
{exceptionContext.Exception.InnerException?.ToString().Replace("\n", "
\n")}" +
- "";
+ $"Message
{exceptionContext.Exception.Message}
" +
+ $"Source
{exceptionContext.Exception.Source}
" +
+ $"StackTrace
{exceptionContext.Exception.StackTrace.Replace("\n", "
\n")}
" +
+ $"InnerException
{exceptionContext.Exception.InnerException?.ToString().Replace("\n", "
\n")}" +
+ "