"""Offline ASP.NET semantic verification lab for Chapter 11 (webpages-helpers)."""
import json
VERSION = "CPython 3.12.14 offline ASP.NET WebPages/Core semantic verifier (IIS/WebMatrix absent)"
def case_builtin_helpers_catalog():
helpers = {
"WebGrid": ["html_table", "formatting", "paging", "sorting"],
"Chart": ["array_source", "database_source", "file_source"],
"WebMail": ["smtp_protocol"],
"WebImage": ["flip", "rotate", "resize", "watermark"],
}
expected = {
"helper_count": 4,
"webgrid_features": 4,
"chart_sources": 3,
"webimage_ops": ["flip", "rotate", "resize", "watermark"],
}
actual = {
"helper_count": len(helpers),
"webgrid_features": len(helpers["WebGrid"]),
"chart_sources": len(helpers["Chart"]),
"webimage_ops": helpers["WebImage"],
}
return {
"name": "builtin_helpers_catalog",
"summary": "核对 WebGrid、Chart、WebMail 与 WebImage 四类核心内建帮助器的能力边界与关键词",
"expected": expected,
"actual": actual,
"passed": actual == expected,
}
def case_webimage_transform_pipeline():
img = {"width": 800, "height": 600, "rotation": 0, "flipped_h": False, "watermark": None}
# Simulate WebImage fluent operations: Resize -> RotateRight -> FlipHorizontal -> AddTextWatermark
img["width"], img["height"] = 400, 300
img["rotation"] = (img["rotation"] + 90) % 360
img["width"], img["height"] = img["height"], img["width"]
img["flipped_h"] = not img["flipped_h"]
img["watermark"] = "Sample"
expected = {"width": 300, "height": 400, "rotation": 90, "flipped_h": True, "watermark": "Sample"}
return {
"name": "webimage_transform_pipeline",
"summary": "模拟 WebImage 缩放、旋转、翻转与文字水印链式变换对图像元数据的确定性影响",
"expected": expected,
"actual": img,
"passed": img == expected,
}
def case_webmatrix_admin_install_workflow():
steps = [
"open_site_workspace",
"click_web_pages_administration",
"login_or_create_password",
"search_helper_package",
"click_install",
]
expected = {
"step_count": 5,
"requires_initial_password": True,
"package_library": "ASP.NET Web Helpers Library",
}
actual = {
"step_count": len(steps),
"requires_initial_password": "login_or_create_password" in steps,
"package_library": "ASP.NET Web Helpers Library",
}
return {
"name": "webmatrix_admin_install_workflow",
"summary": "核对 WebMatrix 中通过 Web Pages Administration 搜索并安装扩展帮助器的五步流程",
"expected": expected,
"actual": actual,
"passed": actual == expected,
}
def case_modern_aspnet_core_equivalents():
migration = {
"WebGrid": "Razor Pages + Tag Helpers / Blazor QuickGrid",
"Chart": "JSON API + Chart.js / ECharts / SkiaSharp",
"WebMail": "MailKit (NuGet)",
"WebImage": "SixLabors.ImageSharp (NuGet)",
"Web Pages Administration": "dotnet add package (NuGet CLI)",
}
expected = {"mapped_count": 5, "uses_nuget_mailkit": True, "uses_imagesharp": True}
actual = {
"mapped_count": len(migration),
"uses_nuget_mailkit": "MailKit" in migration["WebMail"],
"uses_imagesharp": "ImageSharp" in migration["WebImage"],
}
return {
"name": "modern_aspnet_core_equivalents",
"summary": "核对传统 ASP.NET Web Helpers 到现代 ASP.NET Core NuGet 生态组件的对应迁移方案",
"expected": expected,
"actual": actual,
"passed": actual == expected,
}
def main():
cases = [
case_builtin_helpers_catalog(),
case_webimage_transform_pipeline(),
case_webmatrix_admin_install_workflow(),
case_modern_aspnet_core_equivalents(),
]
print(json.dumps({"version": VERSION, "cases": cases}, ensure_ascii=False, indent=2))
if __name__ == "__main__":
main()
本例需在 Windows x64、CPython 3.12.14 离线 ASP.NET WebPages / Razor 语义验证器(本机未启动 IIS / IIS Express / WebMatrix 宿主环境)。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:Windows x64、CPython 3.12.14 离线 ASP.NET WebPages / Razor 语义验证器(本机未启动 IIS / IIS Express / WebMatrix 宿主环境)。
入口文件:projects/razor-webpages-helpers-lab/explore-webpages-helpers.py
本地运行步骤快速上手
- 点击上方“保存源码”保存为
explore-webpages-helpers.py,或下载右侧课程工程包。 - 确认本地已准备 Windows x64、CPython 3.12.14 离线 ASP.NET WebPages / Razor 语义验证器(本机未启动 IIS / IIS Express / WebMatrix 宿主环境)。。
- 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载
课程关联工程包(登记关联55章) · 含当前章节或实例 · mbskycom202612a2925.zip
课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a2952.zip