在测试项目中模拟 Umbraco 配置
Mock Umbraco configuration in test project
当 运行 对使用某些 Umbraco 核心扩展的代码进行单元测试时,例如 string.ToUrlSegement()
,抛出以下错误:
System.Configuration.ConfigurationErrorsException: Could not load the Umbraco.Core.Configuration.UmbracoSettings.IUmbracoSettingsSection from config file, ensure the web.config and umbracoSettings.config files are formatted correctly
你如何防止这种情况发生?
除了将所有 Umbraco 设置复制到您的测试项目中 app.config,您还可以添加以下配置:
<configSections>
<sectionGroup name="umbracoConfiguration">
<section name="settings" type="Umbraco.Core.Configuration.UmbracoSettings.UmbracoSettingsSection, Umbraco.Core" requirePermission="false" />
</sectionGroup>
</configSections>
这可以防止在使用依赖于主项目配置的 Umbraco 核心函数时抛出异常。
发现了这个和其他一些重要提示 here。
当 运行 对使用某些 Umbraco 核心扩展的代码进行单元测试时,例如 string.ToUrlSegement()
,抛出以下错误:
System.Configuration.ConfigurationErrorsException: Could not load the Umbraco.Core.Configuration.UmbracoSettings.IUmbracoSettingsSection from config file, ensure the web.config and umbracoSettings.config files are formatted correctly
你如何防止这种情况发生?
除了将所有 Umbraco 设置复制到您的测试项目中 app.config,您还可以添加以下配置:
<configSections>
<sectionGroup name="umbracoConfiguration">
<section name="settings" type="Umbraco.Core.Configuration.UmbracoSettings.UmbracoSettingsSection, Umbraco.Core" requirePermission="false" />
</sectionGroup>
</configSections>
这可以防止在使用依赖于主项目配置的 Umbraco 核心函数时抛出异常。
发现了这个和其他一些重要提示 here。