防止 Visual Studio Web Test 更改请求详细信息

发布于 2024-08-27 01:42:35 字数 456 浏览 9 评论 0原文

我有一个接受分析服务的 Xmla 查询的服务,通常这些查询本身会有一个字符串,其中包含一个看起来像

{{[Time].[Year].[All]}}

记录这些请求的片段,效果很好,但是当我尝试重新运行测试时,我收到一个错误测试运行程序...

请求失败:发生异常:WebTestContext 中没有名称为“[Time].[Year].[All]”的上下文参数

这在一段时间内令人困惑,但是当我要求 VS 生成编码时测试版本我能够更好地看到问题。 VS 搜索“{{”和“}}”标记并进行更改,考虑到这些区域引用上下文参数,代码看起来像

this.Context["\n\t[Time].[Year].[All]"].ToString()

有人知道如何指示 Visual Studio 不执行此替换操作吗?或者解决这个问题的另一种方法?

I have a service that accepts Xmla queries for Analysis services, often times those queries themselves will have a string that contains a fragment that looks something like

{{[Time].[Year].[All]}}

Recording these requests works fine but when I try to re-run the test I get an error from the test runner...

Request failed: Exception occurred: There is no context parameter with the name ' [Time].[Year].[All]' in the WebTestContext

This was confusing for some time but when I asked VS to generate a coded version of the test I was able to see the problem a bit better. VS searches for the '{{' and '}}' tokens and makes changes, considering those areas to refer to Context parameters, the code looks like

this.Context["\n\t[Time].[Year].[All]"].ToString()

Anyone know how to instruct Visual Studio to not perform this replacement operation? Or another way around this issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

轻许诺言 2024-09-03 01:42:35

使用双花​​括号,例如。 “{{ }}”是多余的。您只需要使用一组大括号,例如。 “{ }”或者如果生成此代码,它也可以处理大括号组之间的空格,例如。 “{{}}”

Using double curly braces eg. "{{ }}" is redundant. You only need to use a single set of braces eg. "{ }" or if this code is generated it will also work with spaces between the sets of braces eg. "{ { } }"

情域 2024-09-03 01:42:35

据我所知,上下文替换行为是自动的且无法控制,但有一些方法可以解决它:

  • 生成编码测试,然后撤消 Visual Studio 所做的操作,例如替换 this.Context[ "\n\t[时间].[年份].[全部]"].ToString()"{{[时间].[年份].[全部]}}" 它出现在任何地方。但这有点糟糕。

  • {{[Time].[Year].[All]}} 字符串放入上下文参数中,并使用该上下文参数而不是原始字符串。 Visual Studio 仅应用一次上下文参数替换,因此它将保留结果字符串值。

  • 第三种可能性是将所有 xmla 字符串 {{[foo]}} 更改为 [[[foo]]],然后编写 WebTestPlugin 或WebTestRequestPlugin 在测试执行期间将 [[[foo]]] 转换回 PreRequest 事件中的 {{[foo]}}。自动替换发生在 PreRequest 之前,因此这是将它们放回大括号的安全时间。

The context-substitution behaviour is automatic and not controllable as far as I know, but there are some ways to work around it:

  • Generate coded tests and then undo what Visual Studio has done, e.g. replace this.Context["\n\t[Time].[Year].[All]"].ToString() with "{{[Time].[Year].[All]}}" everywhere it appears. This is kind of awful though.

  • Put the {{[Time].[Year].[All]}} string into a context parameter and use that context parameter instead of the raw string. Visual Studio only applies context parameter substitution once, so it will leave the resulting string value alone.

  • A third possibility is to alter all of the xmla strings {{[foo]}} to be [[[foo]]] and then write a WebTestPlugin or WebTestRequestPlugin that converts [[[foo]]] back to {{[foo]}} in the PreRequest event during test execution. The automatic substitution happens before PreRequest so that is a safe time to put them back to curly-braces.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文