使用 RazorEngine 测试 cshtml 文件的编译

问题描述

我想对我的 cshtml 文件进行单元测试以确保它们能够成功编译,因为最近我遇到了一些问题,在运行时由于期望属性不存在的视图而出现故障。我正在尝试使用 RazorEngine 来检查这一点,这是我在单元测试中的尝试:

      public void LayoutCshtml_AnyCase_ViewCompilesSuccessfully()
        {
            var model = new Model();

            var templateName = File.ReadAllText("PathToView/_Layout.cshtml");
            var result = Engine.Razor.runcompile(templateName,"key",typeof(Model),model);
            //Assertion will go here 

        }

我稍后会添加断言,但目前只想编译视图。 templateName 正确选择了正确的 .cshtml 但由于错误导致结果失败:

预定义类型 'System.Runtime.CompilerServices.ExtensionAttribute' 定义在 全局别名中的多个程序集;

有人熟悉使用 RazorEngine 进行测试吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)