c# - Visual Studio 2015: WebTest Validate Response with Regex -


i'm try use regex validate response text in webtest. validationrulefindtext class, have option use regex validate response text web request. example:

response text: {"success":true, "data":"foo bar"}

validationrulefindtext validationrule = new validationrulefindtext(); validationrule.findtext = @"/(/""success/"":true)/ig"; validationrule.ignorecase = true; validationrule.useregularexpression = true; validationrule.passiftextfound = true; foobarrequest.validateresponse += new eventhandler<validationeventargs>    (validationrule3.validate); 

for reason it's not recognizing validationrule.findtext regex , fails because literally can't find /(/"success/":true)/ig in response. if familiar this, appreciated :)

this easy work out using visual studio. take .webtest file can used sandbox file. add find text validation rule correct settings , run "generate code" command. correct code validation seen in generated .cs file.

for example string in question, search string {"success":true, "data":"foo bar"} generates line below. other validation rule lines same in question.

validationrule1.findtext = "{\"success\":true, \"data\":\"foo bar\"}"; 

finally, there nothing search string needs regular expression. non-regular-expression validation rule suffice.


the line in question has validationrule.findtext = @"/(/""success/"":true)/ig"; appears appealing way regular expressions used in other languages. enclosing / characters , trailing ig should not used. functionality achieved other means.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

c# - Json.Net Serialize String from URI -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -