質問

So I have the following code:

    public override void Extract(object sender, ExtractionEventArgs e)
    {
            if (e.Response.HtmlDocument != null)
            {

                var myParam = e.Request.QueryStringParameters.Where(parameter => parameter.Name == QueryName).Select(parameter => parameter.Value).Distinct();

                myParam.

                // add the extracted value to the web performance test context
                e.WebTest.Context.Add(this.ContextParameterName, myParam.ToString());
                e.Success = true;
                return;

            }


        // If the extraction fails, set the error text that the user sees
        e.Success = false;
        e.Message = String.Format(CultureInfo.CurrentCulture, "Not Found: {0}", QueryName);
    }

It's returning:

System.Linq.Enumerable+<DistinctItem>d_81`1[system.string]

I am expecting something along the lines of:

0152-1231-1231-123d

My question is how do I extract the querystring's actual value from extractioneventargs. They say it's possible, but I have no idea.

役に立ちましたか?

解決

You could use string.Join:

string resultAsString = string.Join("-", myParam);
e.WebTest.Context.Add(this.ContextParameterName, resultAsString);

I'm assuming here that the query string parameter values are 0152, 1231, etc, and you want to combine them with dashes.

Since WebTest.Context.Add can accept an object, you could also add the result as an array, if that suits your purposes:

e.WebTest.Context.Add(this.ContextParameterName, myParam.ToArray());

(Note that this string System.Linq.Enumerable+<DistinctItem>d_81``1[system.string] is the type name, which is what ToString() returns for any object by default (unless it's been overridden).)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top