开发者

Prevent Visual Studio Web Test from changing request details

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 instru开发者_Python百科ct Visual Studio to not perform this replacement operation? Or another way around this issue?


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. "{ { } }"


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜