【问题标题】:Visual Studio 2015 IntelliTest bug on Azure API Apps?Azure API 应用程序上的 Visual Studio 2015 IntelliTest 错误?
【发布时间】:2015-10-15 14:51:39
【问题描述】:
使用“Azure API 应用程序(预览版)”模板在默认/空白 ASP.net 应用程序上运行 IntelliTest 时,IntelliTest 找不到要测试的内容。我不确定这是设计使然、错误还是尚不支持。有谁知道解决方法?
IntelliTest 输出窗口显示“已退出监控进程,找不到任何要运行的测试 (-1013 - 0xfffffc0b)”。我已确保项目以 x86 为目标。
如果我使用“Web API”模板,IntelliTest 会正确生成测试结果(在下面的第 4 步中,选择 Web API 而不是 Azure API 应用程序)。我现在已经在 2 台机器上验证了上述行为。
复制:
- 打开 VS 2015 企业版
- 文件 -> 新建项目
- 在 Templates -> Visual C# -> Cloud 下,选择“ASP.net Web Application”
- 选择名称位置并单击确定,在下面的屏幕中选择“Azure API 应用程序(预览版)”并单击确定。
- 当项目加载时,导航到“ValuesController”。
- 在任一默认 Get() 方法中单击鼠标右键并选择“运行 IntelliTest”,如下所示
- 打开输出窗口并从“显示输出自”下拉菜单中选择“IntelliTest”并观察上面的消息(...找不到要运行的任何测试)
【问题讨论】:
标签:
asp.net
visual-studio
azure-api-apps
intellitest
【解决方案1】:
最终将此问题归结为 Swashbuckle 和 intelliTest 之间的一些不兼容(api 应用程序使用 Swasbuckle 为 API 生成 Swagger 文档)。
要解决此问题,请打开 API App 项目的 App_Start 文件夹中的 SwaggerConfig.cs,并删除以下继承自 IOperationFilter 的类。这样做的缺点是没有将您的参数连接到 swagger 文档中,这是我无论如何都不喜欢的(默认模型更适合从中读取一长串参数)。
internal class IncludeParameterNamesInOperationIdFilter : IOperationFilter
{
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
if (operation.parameters != null)
{
// Select the capitalized parameter names
var parameters = operation.parameters.Select(
p => CultureInfo.InvariantCulture.TextInfo.ToTitleCase(p.name));
// Set the operation id to match the format "OperationByParam1AndParam2"
operation.operationId = $"{operation.operationId}By{string.Join("And", parameters)}";
}
}
}