This document provides essential information for developers and automated agents working on the VAR.WebFormsCore project.
- .NET 10.0 SDK or higher.
- The project targets
netstandard2.0(core library) andnet9.0(AspNetCore integration and tests).
To build the entire solution, run the following command from the root directory:
dotnet build VAR.WebFormsCore.slnxVAR.WebFormsCore: The core library containing WebForms-like controls and logic.VAR.WebFormsCore.AspNetCore: Integration layer for ASP.NET Core.VAR.WebFormsCore.Tests: Unit tests for the core library.VAR.WebFormsCore.TestWebApp: A sample web application for manual testing and demonstration.
Tests are implemented using xUnit. To run all tests in the solution:
dotnet test VAR.WebFormsCore.Tests/VAR.WebFormsCore.Tests.csproj- Create a new test class in the
VAR.WebFormsCore.Testsproject (typically underCode/,Controls/, orPages/). - Use the
[Fact]attribute for simple tests or[Theory]for data-driven tests. - Follow the naming convention:
MethodName__Scenario__ExpectedResult.
Below is a basic example of a unit test for this project:
using Xunit;
using VAR.WebFormsCore.Code;
namespace VAR.WebFormsCore.Tests.Code;
public class DemoTest
{
[Fact]
public void DemoTest__SimpleAssertion__Success()
{
// Arrange
var value = 1;
// Act
var result = value + 1;
// Assert
Assert.Equal(2, result);
}
}- Naming Conventions: Use
PascalCasefor classes and methods. Use_camelCasefor private fields. - File Scoped Namespaces: Use file-scoped namespaces (e.g.,
namespace VAR.WebFormsCore.Tests.Code;) to reduce indentation. - Regions: The codebase sometimes uses
#regionto group related tests or methods. - Control Development: When creating new controls, ensure they inherit from appropriate base classes in
VAR.WebFormsCore.Controls. - Embedded Resources: JavaScript and CSS files in
VAR.WebFormsCoreare often marked asEmbeddedResourceto be served by the library.
- You can use
VAR.WebFormsCore.TestWebAppto debug the library's behavior in a real ASP.NET Core environment. - Use
Console.WriteLineor standard logging for debugging during test execution.
The framework uses a decoupled architecture to handle HTTP requests:
- Host Integration: An adapter (like
VAR.WebFormsCore.AspNetCore) receives the native HTTP request. - Context Abstraction: The native request is wrapped in an
IWebContextimplementation (e.g.,AspnetCoreWebContext). - Routing: The
GlobalRouter.RouteRequest(IWebContext)method determines which handler should process the request based on the URL path. - Handler Execution: An
IHttpHandler(usually aPage) is instantiated and itsProcessRequest(IWebContext)method is called to generate the response.
IWebContext: Abstraction of the HTTP context (Request, Response, Cookies, Headers). Implementing this allows the core library to run on any HTTP framework (ASP.NET Core, Katana, or even a custom socket-based server).IHttpHandler: Interface for objects that process requests. BothPageand resource bundlers implement this.IGlobalConfig: Central configuration for the application (Title, Author, Default Handler, Authentication logic).
The framework includes built-in handlers for CSS and JS bundling:
- Directories Convention: By default, they look for files in the
Styles/andScripts/directories respectively. - Internal (Embedded) Resources: They first bundle files marked as
EmbeddedResourcein theVAR.WebFormsCoreassembly (located in theStyles/andScripts/folders of the core project). - External Files: They then append any files found in the physical
Styles/andScripts/directories of the running application's content root. - Usage:
PageCommonautomatically includes links to these bundlers in the generated HTML.