蓝色天空.知识 · 实践 · 创造
我的收藏
在线代码实验室

离线校验 MvcDemo 新建向导选项、CRUD 能力闭环与 dotnet new mvc 脚手架对照

PYTHONWindows x64、CPython 3.12.14 离线 ASP.NET Razor / MVC 语义验证器(未启动 Visual Studio / IIS / ASP.NET MVC 运行时宿主)。explore-app.py
explore-app.py131 行
"""Offline ASP.NET MVC application creation verification lab for Chapter 27 (mvc-app)."""
import json

VERSION = "CPython 3.12.14 offline ASP.NET MVC application scaffold semantic verifier (IIS/ASP.NET host absent)"


def case_mvc_internet_app_template_options():
    wizard = {
        "language_group": "Visual C#",
        "project_template": "ASP.NET MVC 3 Web Application",
        "project_name": "MvcDemo",
        "location": r"C:\projects\MvcDemo",
        "sub_template": "Internet Application",
        "view_engine": "Razor",
        "html5_markup": True,
    }
    expected = {
        "project_name": "MvcDemo",
        "view_engine": "Razor",
        "html5_markup": True,
        "sub_template": "Internet Application",
    }
    actual = {
        "project_name": wizard["project_name"],
        "view_engine": wizard["view_engine"],
        "html5_markup": wizard["html5_markup"],
        "sub_template": wizard["sub_template"],
    }
    return {
        "name": "mvc_internet_app_template_options",
        "summary": "校验新建 MvcDemo Internet Application 的语言、模板、Razor 视图引擎与 HTML5 标记选项",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def case_mvc_project_crud_capabilities():
    records = {}
    records[1] = {"title": "Psycho", "director": "Alfred Hitchcock"}
    records[2] = {"title": "La Dolce Vita", "director": "Federico Fellini"}
    records[1]["title"] = "Psycho (1960)"
    listed_titles = [records[k]["title"] for k in sorted(records)]
    del records[2]
    expected = {
        "supports_crud": ["Create", "Read", "Update", "Delete"],
        "listed_before_delete": ["Psycho (1960)", "La Dolce Vita"],
        "remaining_count": 1,
    }
    actual = {
        "supports_crud": ["Create", "Read", "Update", "Delete"],
        "listed_before_delete": listed_titles,
        "remaining_count": len(records),
    }
    return {
        "name": "mvc_project_crud_capabilities",
        "summary": "验证教学目标 Internet 应用程序所需的增删改查(Create/Read/Update/Delete)数据操作闭环",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def case_mvc_demo_scaffold_manifest():
    initial_tree = [
        "App_Data/",
        "Content/Site.css",
        "Controllers/AccountController.cs",
        "Controllers/HomeController.cs",
        "Models/AccountModels.cs",
        "Scripts/modernizr-1.7.min.js",
        "Views/Home/Index.cshtml",
        "Views/Home/About.cshtml",
        "Views/Shared/_Layout.cshtml",
        "Global.asax",
        "Web.config",
    ]
    top_dirs = sorted({p.split("/")[0] for p in initial_tree if "/" in p})
    expected = {
        "top_dirs": ["App_Data", "Content", "Controllers", "Models", "Scripts", "Views"],
        "has_layout": True,
        "has_web_config": True,
    }
    actual = {
        "top_dirs": top_dirs,
        "has_layout": "Views/Shared/_Layout.cshtml" in initial_tree,
        "has_web_config": "Web.config" in initial_tree,
    }
    return {
        "name": "mvc_demo_scaffold_manifest",
        "summary": "校验 Internet Application 模板生成的标准 6 大目录与根级配置文件清单",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def case_legacy_vs_dotnet_cli_creation():
    cli_command = ["dotnet", "new", "mvc", "-n", "MvcDemo"]
    expected = {
        "cli_joined": "dotnet new mvc -n MvcDemo",
        "cross_platform": True,
        "default_view_extension": ".cshtml",
    }
    actual = {
        "cli_joined": " ".join(cli_command),
        "cross_platform": True,
        "default_view_extension": ".cshtml",
    }
    return {
        "name": "legacy_vs_dotnet_cli_creation",
        "summary": "对照传统 Visual Web Developer 向导与现代 ASP.NET Core `dotnet new mvc -n MvcDemo` 创建命令",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def main():
    cases = [
        case_mvc_internet_app_template_options(),
        case_mvc_project_crud_capabilities(),
        case_mvc_demo_scaffold_manifest(),
        case_legacy_vs_dotnet_cli_creation(),
    ]
    print(json.dumps({"version": VERSION, "cases": cases}, ensure_ascii=False, indent=2))


if __name__ == "__main__":
    main()
本例需在 Windows x64、CPython 3.12.14 离线 ASP.NET Razor / MVC 语义验证器(未启动 Visual Studio / IIS / ASP.NET MVC 运行时宿主)。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程

运行环境:Windows x64、CPython 3.12.14 离线 ASP.NET Razor / MVC 语义验证器(未启动 Visual Studio / IIS / ASP.NET MVC 运行时宿主)。

入口文件:projects/mvc-app-lab/explore-app.py

本地运行步骤快速上手
  1. 点击上方“保存源码”保存为 explore-app.py,或下载右侧课程工程包。
  2. 确认本地已准备 Windows x64、CPython 3.12.14 离线 ASP.NET Razor / MVC 语义验证器(未启动 Visual Studio / IIS / ASP.NET MVC 运行时宿主)。。
  3. 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载

下载课程关联工程包:MVC

课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a2848.zip

下载课程关联工程包:MVC

课程关联工程包(登记关联55章) · 含当前章节或实例 · mbskycom202612a2870.zip
SITE SEARCH

搜索教程、工具与资讯

热门搜索

JavaScriptJSON格式化正则表达式AI 编程AI 翻译AI导航专题标签
Esc 关闭

欢迎登录蓝色天空网

使用会员账号,继续你的学习