I need to create a ValidationRule to test response bytes including responses for dependent requests. It is easy task to get response bytes for main requests, but I can not access responses for dependent requests. I have no idea how to do that.
public class WebTest1Coded : WebTest
{
public WebTest1Coded()
{
this.PreAuthenticate = true;
}
public long ResponseBytesLength { get; set; }
public override IEnumerator<WebTestRequest> GetRequestEnumerator()
{
if ((this.Context.ValidationLevel >= Microsoft.VisualStudio.TestTools.WebTesting.ValidationLevel.Low))
{
ValidationResponseRuleNumberOfBytes validationRule3 = new ValidationResponseRuleNumberOfBytes();
this.ValidateResponseOnPageComplete += new EventHandler<ValidationEventArgs>(validationRule3.Validate);
}
WebTestRequest request1 = new WebTestRequest("http://localhost/open.aspx");
request1.ThinkTime = 2;
yield return request1;
request1 = null;
}
}
public class ValidationResponseRuleNumberOfBytes : ValidationRule
{
public override string RuleName
{
get { return "Validate Page Size"; }
}
public override string RuleDescription
{
get { return "Validates that the page is less then 300 000 bytes."; }
}
public override void Validate(object sender, ValidationEventArgs e)
{
if (e.Response.HtmlDocument != null)
{
e.Message = string.Format("Page length is {0}", e.Response.BodyBytes.Length);
e.IsValid = e.Response.BodyBytes.Length < 300000;
}
}
}