"""Offline ASP.NET semantic verification lab for Chapter 01 (tutorial)."""
import json
import shutil
VERSION = "CPython 3.12.14 offline ASP.NET WebPages/Core semantic verifier (IIS/WebMatrix absent)"
def case_runtime_host_probe():
iis_express = shutil.which("iisexpress")
webmatrix = shutil.which("webmatrix")
aspnet_compiler = shutil.which("aspnet_compiler")
expected = {
"iisexpress_found": False,
"webmatrix_found": False,
"aspnet_compiler_found": False,
"offline_verifier": True,
}
actual = {
"iisexpress_found": iis_express is not None,
"webmatrix_found": webmatrix is not None,
"aspnet_compiler_found": aspnet_compiler is not None,
"offline_verifier": iis_express is None and webmatrix is None,
}
return {
"name": "runtime_host_probe",
"summary": "如实探测本机 IIS Express、WebMatrix 与 aspnet_compiler 工具,确认当前运行在离线语义验证环境",
"expected": expected,
"actual": actual,
"passed": actual == expected,
}
def case_three_aspnet_models_catalog():
models = [
{
"key": "Web Pages",
"pattern": "single-page",
"entry_style": "Razor (.cshtml/.vbhtml) + Web Helpers",
"modern_successor": "ASP.NET Core Razor Pages",
},
{
"key": "MVC",
"pattern": "model-view-controller",
"entry_style": "Model(数据) + View(显示) + Controller(输入)",
"modern_successor": "ASP.NET Core MVC",
},
{
"key": "Web Forms",
"pattern": "event-driven",
"entry_style": "Server Controls + Server Events + Code-Behind (.aspx)",
"modern_successor": "ASP.NET Core Blazor / Razor Pages",
},
]
expected = {
"count": 3,
"keys": ["Web Pages", "MVC", "Web Forms"],
"mvc_components": 3,
"all_have_modern_successor": True,
}
actual = {
"count": len(models),
"keys": [m["key"] for m in models],
"mvc_components": len(["Model", "View", "Controller"]),
"all_have_modern_successor": all(m["modern_successor"].startswith("ASP.NET Core") for m in models),
}
return {
"name": "three_aspnet_models_catalog",
"summary": "核对 ASP.NET 三大传统开发模式(Web Pages、MVC、Web Forms)定位及现代 ASP.NET Core 对应演进路线",
"expected": expected,
"actual": actual,
"passed": actual == expected,
}
def case_language_and_prerequisite_matrix():
languages = ["C#", "VB.NET"]
web_stack = ["HTML", "CSS", "JavaScript", "Server Script"]
modern_web_topics = ["HTML5", "CSS3", "jQuery"]
expected = {
"dual_language_support": True,
"stack_layers": 4,
"modern_topics_count": 3,
}
actual = {
"dual_language_support": set(languages) == {"C#", "VB.NET"},
"stack_layers": len(web_stack),
"modern_topics_count": len(modern_web_topics),
}
return {
"name": "language_and_prerequisite_matrix",
"summary": "校验 ASP.NET 教学栈前置基础(HTML/CSS/JavaScript)及 C#/VB 双语言实例覆盖约定",
"expected": expected,
"actual": actual,
"passed": actual == expected,
}
def case_official_dotnet_references():
refs = [
("Microsoft Learn: ASP.NET 概览", "https://learn.microsoft.com/zh-cn/aspnet/overview"),
("Microsoft Learn: ASP.NET Core Razor Pages", "https://learn.microsoft.com/zh-cn/aspnet/core/razor-pages/"),
]
expected = {"count": 2, "all_https": True, "host": "learn.microsoft.com"}
actual = {
"count": len(refs),
"all_https": all(url.startswith("https://") for _, url in refs),
"host": refs[0][1].split("/")[2],
}
return {
"name": "official_dotnet_references",
"summary": "校验微软官方 ASP.NET 与 ASP.NET Core Razor Pages 文档参考链接",
"expected": expected,
"actual": actual,
"passed": actual == expected,
}
def main():
cases = [
case_runtime_host_probe(),
case_three_aspnet_models_catalog(),
case_language_and_prerequisite_matrix(),
case_official_dotnet_references(),
]
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-aspnet-tutorial-lab/explore-aspnet-tutorial.py
本地运行步骤快速上手
- 点击上方“保存源码”保存为
explore-aspnet-tutorial.py,或下载右侧课程工程包。 - 确认本地已准备 Windows x64、CPython 3.12.14 离线 ASP.NET WebPages / Razor 语义验证器(本机未启动 IIS / IIS Express / WebMatrix 宿主环境)。。
- 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载
课程关联工程包(登记关联55章) · 含当前章节或实例 · mbskycom202612a2925.zip
课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a2922.zip