public override void Validate(object sender, ValidationEventArgs e)
        {
            string response = e.Response.BodyString;

            if (this.CheckEmptyResponse == true && string.IsNullOrWhiteSpace(response))
            {
                e.IsValid = true;
                return;
            }
            if (string.IsNullOrWhiteSpace(response))
            {
                e.IsValid = false;
                e.Message = "Response content was empty";
                return;
            }
            JObject json  = JObject.Parse(response);
            string  value = JObjectHelper.GetValueByPath(json, this.Path);

            e.IsValid = value == this.ExpectedValue;
        }
示例#2
0
 public override void Extract(object sender, ExtractionEventArgs e)
 {
     try
     {
         string jsonResponse = e.Response.BodyString;
         if (string.IsNullOrWhiteSpace(jsonResponse))
         {
             return;
         }
         JObject json  = JObject.Parse(jsonResponse);
         string  value = JObjectHelper.GetValueByPath(json, this.Path);
         e.WebTest.Context.Add(this.ContextParameterName, value);
         ITestContext context = e.WebTest.Context[TestContextConst.ContextKey] as ITestContext;
         context.Add(this.ContextParameterName, value);
         //context.SetEventArgs(e);
         //TestContext.Context.Add(this.ContextParameterName, value);
         e.Success = true;
     }
     catch (Exception ex)
     {
         e.Success = false;
         e.Message = ex.Message;
     }
 }