本文整理汇总了C#中WebTestRequest类的典型用法代码示例。如果您正苦于以下问题:C# WebTestRequest类的具体用法?C# WebTestRequest怎么用?C# WebTestRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WebTestRequest类属于命名空间,在下文中一共展示了WebTestRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetRequestEnumerator
public override IEnumerator<WebTestRequest> GetRequestEnumerator()
{
WebTestRequest logonRequest = new WebTestRequest(Utilities.BaseUrl + Constants.LogonPageUrlSuffix);
logonRequest.ExpectedResponseUrl = Utilities.BaseUrl + Constants.LogonPageUrlSuffix;
ExtractHiddenFields extractionRule1 = ValidationRuleHelper.GetDefaultExtractHiddenFields();
logonRequest.ExtractValues += new EventHandler<ExtractionEventArgs>(extractionRule1.Extract);
yield return logonRequest;
logonRequest = null;
//Send a post request with the appropriate form parameters for crednetials.
WebTestRequest logonPostRequest = new WebTestRequest(Utilities.BaseUrl + Constants.LogonPageUrlSuffix);
logonPostRequest.Method = "POST";
logonPostRequest.ExpectedResponseUrl = Utilities.BaseUrl;
FormPostHttpBody request10Body = new FormPostHttpBody();
request10Body.FormPostParameters.Add("__RequestVerificationToken", this.Context["$HIDDEN1.__RequestVerificationToken"].ToString());
request10Body.FormPostParameters.Add(Constants.UserNameOrEmailFormField, this.Context["LogOnCredentials.LogonCredentials#csv.UserNameOrEmail"].ToString());
request10Body.FormPostParameters.Add(Constants.PasswordFormField, this.Context["LogOnCredentials.LogonCredentials#csv.Password"].ToString());
logonPostRequest.Body = request10Body;
WebTestRequest request10Dependent1 = new WebTestRequest(Utilities.BaseUrl + Constants.StatsPageUrlSuffix);
logonPostRequest.DependentRequests.Add(request10Dependent1);
if ((this.Context.ValidationLevel >= Microsoft.VisualStudio.TestTools.WebTesting.ValidationLevel.High))
{
//After logon, the user name should appear as a hyperlink the reponse URL
ValidateHtmlTagInnerText loggedOnUserNameValidationRule = ValidationRuleHelper.GetValidationRuleForHtmlTagInnerText(HtmlTextWriterTag.A.ToString(), HtmlTextWriterAttribute.Href.ToString(), "/account", "NugetTestAccount");
logonPostRequest.ValidateResponse += new EventHandler<ValidationEventArgs>(loggedOnUserNameValidationRule.Validate);
}
yield return logonPostRequest;
logonPostRequest = null;
}
示例2: GetHttpRequestForUrl
/// <summary>
/// Returns a WebRequest for the given Url.
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
public static WebTestRequest GetHttpRequestForUrl(string url)
{
var getRequest = new WebTestRequest(url);
var extractionRule = GetDefaultExtractHiddenFields();
getRequest.ExtractValues += extractionRule.Extract;
return getRequest;
}
示例3: GetRequestEnumerator
public override IEnumerator<WebTestRequest> GetRequestEnumerator()
{
//send a request to home page and check for security headers.
WebTestRequest homePageRequest = new WebTestRequest(UrlHelper.BaseUrl);
homePageRequest.ParseDependentRequests = false;
ValidationRuleFindHeaderText homePageTextValidationRule = new ValidationRuleFindHeaderText(
@"X-Frame-Options: deny
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Strict-Transport-Security: max-age=31536000");
homePageRequest.ValidateResponse += new EventHandler<ValidationEventArgs>(homePageTextValidationRule.Validate);
yield return homePageRequest;
homePageRequest = null;
//send a request to Packages page and check for security headers.
WebTestRequest packagesPageRequest = new WebTestRequest(UrlHelper.PackagesPageUrl);
packagesPageRequest.ParseDependentRequests = false;
ValidationRuleFindHeaderText packagesPageTextValidationRule = new ValidationRuleFindHeaderText(
@"X-Frame-Options: deny
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Strict-Transport-Security: max-age=31536000");
packagesPageRequest.ValidateResponse += new EventHandler<ValidationEventArgs>(packagesPageTextValidationRule.Validate);
yield return packagesPageRequest;
packagesPageRequest = null;
}
示例4: GetRequestEnumerator
public override IEnumerator<WebTestRequest> GetRequestEnumerator()
{
// Инициализация правил проверки, применяемых ко всем запросам в веб-тесте
if ((this.Context.ValidationLevel >= Microsoft.VisualStudio.TestTools.WebTesting.ValidationLevel.High))
{
ValidationRuleRequiredTag validationRule1 = new ValidationRuleRequiredTag();
validationRule1.RequiredTagName = "User";
validationRule1.MinOccurrences = 1;
this.ValidateResponse += new EventHandler<ValidationEventArgs>(validationRule1.Validate);
}
if ((this.Context.ValidationLevel >= Microsoft.VisualStudio.TestTools.WebTesting.ValidationLevel.High))
{
ValidationRuleRequestTime validationRule2 = new ValidationRuleRequestTime();
validationRule2.MaxRequestTime = 1000;
this.ValidateResponse += new EventHandler<ValidationEventArgs>(validationRule2.Validate);
}
WebTestRequest request1 = new WebTestRequest("http://193.226.64.163/SANDBOXWebServiceDev/Service1.asmx");
request1.Timeout = 3;
request1.Method = "POST";
request1.Encoding = System.Text.Encoding.GetEncoding("utf-8");
request1.Headers.Add(new WebTestRequestHeader("SOAPAction", "http://tempuri.org/GetAllUsers"));
StringHttpBody request1Body = new StringHttpBody();
request1Body.ContentType = "text/xml";
request1Body.InsertByteOrderMark = false;
request1Body.BodyString = @"<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">
<soap:Body>
<GetAllUsers xmlns=""http://tempuri.org/"" />
</soap:Body>
</soap:Envelope>";
request1.Body = request1Body;
yield return request1;
request1 = null;
}
示例5: GetRequestEnumerator
public override IEnumerator<WebTestRequest> GetRequestEnumerator()
{
WebTestRequest registerPageRequest = new WebTestRequest(Utilities.BaseUrl + Constants.RegisterPageUrlSuffix);
registerPageRequest.ThinkTime = 31;
ExtractHiddenFields extractionRule1 = new ExtractHiddenFields();
extractionRule1.Required = true;
extractionRule1.HtmlDecode = true;
extractionRule1.ContextParameterName = "1";
registerPageRequest.ExtractValues += new EventHandler<ExtractionEventArgs>(extractionRule1.Extract);
yield return registerPageRequest;
registerPageRequest = null;
WebTestRequest registerPagePostRequest = new WebTestRequest(Utilities.BaseUrl + Constants.RegisterPageUrlSuffix);
registerPagePostRequest.Method = "POST";
registerPagePostRequest.ExpectedResponseUrl = Utilities.BaseUrl + Constants.RegistrationPendingPageUrlSuffix;
//create a form and set the UserName, Email and password as form post parameters.
//We just need to set some unique user name and Email.
FormPostHttpBody registerNewUserFormPost = new FormPostHttpBody();
registerNewUserFormPost.FormPostParameters.Add("__RequestVerificationToken", this.Context["$HIDDEN1.__RequestVerificationToken"].ToString());
registerNewUserFormPost.FormPostParameters.Add(Constants.EmailAddressFormField, DateTime.Now.Ticks.ToString() + "@gmail.com");
registerNewUserFormPost.FormPostParameters.Add(Constants.UserNameFormField, DateTime.Now.Ticks.ToString());
registerNewUserFormPost.FormPostParameters.Add(Constants.PasswordFormField, "xxxxxxx");
registerNewUserFormPost.FormPostParameters.Add(Constants.ConfirmPasswordFormField, "xxxxxxx");
registerPagePostRequest.Body = registerNewUserFormPost;
//Validate the response to make sure that it has the pending confirmation text in it.
if ((this.Context.ValidationLevel >= Microsoft.VisualStudio.TestTools.WebTesting.ValidationLevel.High))
{
ValidationRuleFindText PendingConfirmationTextRule = ValidationRuleHelper.GetValidationRuleForFindText(Constants.PendingConfirmationText);
registerPagePostRequest.ValidateResponse += new EventHandler<ValidationEventArgs>(PendingConfirmationTextRule.Validate);
}
yield return registerPagePostRequest;
registerPagePostRequest = null;
}
示例6: GetRequestEnumerator
public override IEnumerator<WebTestRequest> GetRequestEnumerator()
{
ExtractHiddenFields defaultExtractionRule = AssertAndValidationHelper.GetDefaultExtractHiddenFields();
//Do initial login
WebTestRequest logonGet = AssertAndValidationHelper.GetLogonGetRequest();
yield return logonGet;
logonGet = null;
WebTestRequest logonPost = AssertAndValidationHelper.GetLogonPostRequest(this);
yield return logonPost;
logonPost = null;
WebTestRequest uploadRequest = AssertAndValidationHelper.GetHttpRequestForUrl(UrlHelper.UploadPageUrl);
yield return uploadRequest;
uploadRequest = null;
// The API key is part of the nuget.config file that is present under the solution dir.
string packageId = DateTime.Now.Ticks.ToString();
string packageFullPath = PackageCreationHelper.CreatePackage(packageId);
WebTestRequest uploadPostRequest = AssertAndValidationHelper.GetUploadPostRequestForPackage(this, packageFullPath);
yield return uploadPostRequest;
uploadPostRequest = null;
WebTestRequest verifyUploadRequest = new WebTestRequest(UrlHelper.VerifyUploadPageUrl);
verifyUploadRequest.ExtractValues += new EventHandler<ExtractionEventArgs>(defaultExtractionRule.Extract);
yield return verifyUploadRequest;
verifyUploadRequest = null;
WebTestRequest verifyUploadPostRequest = AssertAndValidationHelper.GetVerifyPackagePostRequestForPackage(this, packageId, "1.0.0");
yield return verifyUploadPostRequest;
verifyUploadPostRequest = null;
}
示例7: GetHttpRequestForUrl
/// <summary>
/// Returns a WebRequest for the given Url.
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
public static WebTestRequest GetHttpRequestForUrl(string url)
{
WebTestRequest getRequest = new WebTestRequest(url);
ExtractHiddenFields extractionRule1 = AssertAndValidationHelper.GetDefaultExtractHiddenFields();
getRequest.ExtractValues += new EventHandler<ExtractionEventArgs>(extractionRule1.Extract);
return getRequest;
}
示例8: GetRequestEnumerator
public override IEnumerator<WebTestRequest> GetRequestEnumerator()
{
//run this test only if read-only mode is set. This is to avoid false failures while doing Run all tests locally.
if (EnvironmentSettings.ReadOnlyMode.Equals("True", StringComparison.OrdinalIgnoreCase))
{
var registerPageRequest = AssertAndValidationHelper.GetHttpRequestForUrl(UrlHelper.LogonPageUrl);
yield return registerPageRequest;
var registerPagePostRequest = new WebTestRequest(UrlHelper.RegisterPageUrl);
registerPagePostRequest.Method = "POST";
registerPagePostRequest.ExpectedResponseUrl = UrlHelper.RegistrationPendingPageUrl;
// Create a form and set the UserName, Email and password as form post parameters.
// We just need to set some unique user name and Email.
var registerNewUserFormPost = new FormPostHttpBody();
registerNewUserFormPost.FormPostParameters.Add("__RequestVerificationToken", Context["$HIDDEN1.__RequestVerificationToken"].ToString());
registerNewUserFormPost.FormPostParameters.Add("LinkingAccount", "false");
registerNewUserFormPost.FormPostParameters.Add(Constants.EmailAddressFormField, DateTime.Now.Ticks + "@live.com"); //add a dummy mail account. This will be fixed once we incorporate the logic to delete user.
registerNewUserFormPost.FormPostParameters.Add(Constants.UserNameFormField, DateTime.Now.Ticks + "NewAccount");
registerNewUserFormPost.FormPostParameters.Add(Constants.RegisterPasswordFormField, "xxXxx1xx");
registerPagePostRequest.Body = registerNewUserFormPost;
registerPagePostRequest.ExpectedHttpStatusCode = 503;
// Validate the response to make sure that it shows the error message for read-only mode.
var readOnlyModeTextRule = AssertAndValidationHelper.GetValidationRuleForFindText(Constants.ReadOnlyModeError);
registerPagePostRequest.ValidateResponse += readOnlyModeTextRule.Validate;
yield return registerPagePostRequest;
}
}
示例9: GetRequestEnumerator
public override IEnumerator<WebTestRequest> GetRequestEnumerator()
{
WebTestRequest registerPageRequest = AssertAndValidationHelper.GetHttpRequestForUrl(UrlHelper.LogonPageUrl);
yield return registerPageRequest;
registerPageRequest = null;
WebTestRequest registerPagePostRequest = new WebTestRequest(UrlHelper.RegisterPageUrl);
registerPagePostRequest.Method = "POST";
registerPagePostRequest.ExpectedResponseUrl = UrlHelper.RegistrationPendingPageUrl;
//create a form and set the UserName, Email and password as form post parameters.
//We just need to set some unique user name and Email.
FormPostHttpBody registerNewUserFormPost = new FormPostHttpBody();
registerNewUserFormPost.FormPostParameters.Add("__RequestVerificationToken", this.Context["$HIDDEN1.__RequestVerificationToken"].ToString());
registerNewUserFormPost.FormPostParameters.Add(Constants.EmailAddressFormField, DateTime.Now.Ticks.ToString() + "@live.com"); //add a dummy mail account. This will be fixed once we incorporate the logic to delete user.
registerNewUserFormPost.FormPostParameters.Add(Constants.UserNameFormField, DateTime.Now.Ticks.ToString() + "NewAccount");
registerNewUserFormPost.FormPostParameters.Add(Constants.PasswordFormField, "xxxxxxx");
registerNewUserFormPost.FormPostParameters.Add(Constants.ConfirmPasswordFormField, "xxxxxxx");
registerNewUserFormPost.FormPostParameters.Add(Constants.AcceptTermsField, "true");
registerPagePostRequest.Body = registerNewUserFormPost;
//Validate the response to make sure that it has the pending confirmation text in it.
ValidationRuleFindText PendingConfirmationTextRule = AssertAndValidationHelper.GetValidationRuleForFindText(Constants.RegisterNewUserPendingConfirmationText);
registerPagePostRequest.ValidateResponse += new EventHandler<ValidationEventArgs>(PendingConfirmationTextRule.Validate);
yield return registerPagePostRequest;
registerPagePostRequest = null;
}
示例10: GetRequestEnumerator
public override IEnumerator<WebTestRequest> GetRequestEnumerator()
{
WebTestRequest registerPageRequest = AssertAndValidationHelper.GetHttpRequestForUrl(UrlHelper.LogonPageUrl);
yield return registerPageRequest;
registerPageRequest = null;
WebTestRequest registerPagePostRequest = new WebTestRequest(UrlHelper.SignInPageUrl);
registerPagePostRequest.Method = "POST";
registerPagePostRequest.ExpectedResponseUrl = UrlHelper.SignInPageUrl;
//create a form and set the UserName, Email and password as form post parameters.
//We just need to set some unique user name and Email.
FormPostHttpBody registerNewUserFormPost = new FormPostHttpBody();
registerNewUserFormPost.FormPostParameters.Add("__RequestVerificationToken", Context["$HIDDEN1.__RequestVerificationToken"].ToString());
registerNewUserFormPost.FormPostParameters.Add("ReturnUrl", "/");
registerNewUserFormPost.FormPostParameters.Add("LinkingAccount", "false");
registerNewUserFormPost.FormPostParameters.Add(Constants.UserNameOrEmailFormField, DateTime.Now.Ticks.ToString() + "@live.com");
registerNewUserFormPost.FormPostParameters.Add(Constants.PasswordFormField, EnvironmentSettings.TestAccountPassword);
registerPagePostRequest.Body = registerNewUserFormPost;
//Validate the response to make sure that it doesn't have the pending confirmation text in it.
ValidationRuleFindText PendingConfirmationTextRule = AssertAndValidationHelper.GetValidationRuleForFindText(Constants.RegisterNewUserPendingConfirmationText, false);
registerPagePostRequest.ValidateResponse += new EventHandler<ValidationEventArgs>(PendingConfirmationTextRule.Validate);
yield return registerPagePostRequest;
registerPagePostRequest = null;
}
示例11: GetRequestEnumerator
public override IEnumerator<WebTestRequest> GetRequestEnumerator()
{
WebTestRequest request1 = new WebTestRequest(Common.userDomain + "GetUserProfile");
request1.Encoding = System.Text.Encoding.GetEncoding("utf-8");
request1.QueryStringParameters.Add("userId", "aaf9a5a7-1f18-4a2d-b108-3ba3a978bdf6", false, false);
request1.ValidateResponse += new EventHandler<ValidationEventArgs>(request1_ValidateResponse);
yield return request1;
request1 = null;
WebTestRequest request2 = new WebTestRequest(Common.userDomain + "GetFriendList");
request2.Encoding = System.Text.Encoding.GetEncoding("utf-8");
request2.QueryStringParameters.Add("userId", "aaf9a5a7-1f18-4a2d-b108-3ba3a978bdf6", false, false);
request2.ValidateResponse += new EventHandler<ValidationEventArgs>(request2_ValidateResponse);
yield return request2;
request2 = null;
WebTestRequest request3 = new WebTestRequest(Common.userDomain + "IsLegalUserName");
request3.Encoding = System.Text.Encoding.GetEncoding("utf-8");
request3.QueryStringParameters.Add("userName", "testtest", false, false);
request3.ValidateResponse += new EventHandler<ValidationEventArgs>(request3_ValidateResponse);
yield return request3;
request3 = null;
WebTestRequest request4 = new WebTestRequest(Common.userDomain + "IsLegalUserName");
request4.Encoding = System.Text.Encoding.GetEncoding("utf-8");
request4.QueryStringParameters.Add("userName", "userwhichnotexist", false, false);
request4.ValidateResponse += new EventHandler<ValidationEventArgs>(request4_ValidateResponse);
yield return request4;
request4 = null;
}
示例12: GetRequestEnumerator
public override IEnumerator<WebTestRequest> GetRequestEnumerator()
{
ExtractHiddenFields defaultExtractionRule = AssertAndValidationHelper.GetDefaultExtractHiddenFields();
//Upload a new package.
string packageId = this.Name + DateTime.Now.Ticks.ToString();
string version = "1.0.0";
AssertAndValidationHelper.UploadNewPackageAndVerify(packageId, version);
//Do initial login to be able to perform edit.
WebTestRequest logonGet = AssertAndValidationHelper.GetLogonGetRequest();
yield return logonGet;
logonGet = null;
WebTestRequest logonPost = AssertAndValidationHelper.GetLogonPostRequest(this);
yield return logonPost;
logonPost = null;
WebTestRequest uploadRequest = AssertAndValidationHelper.GetHttpRequestForUrl(UrlHelper.UploadPageUrl);
yield return uploadRequest;
if (this.LastResponse.ResponseUri.ToString().Contains("verify-upload"))
{
WebTestRequest cancelGet = AssertAndValidationHelper.GetCancelGetRequest();
yield return cancelGet;
cancelGet = null;
uploadRequest = AssertAndValidationHelper.GetHttpRequestForUrl(UrlHelper.UploadPageUrl);
yield return uploadRequest;
}
uploadRequest = null;
// The API key is part of the nuget.config file that is present under the solution dir.
string packageFullPath = PackageCreationHelper.CreatePackage(packageId);
WebTestRequest uploadPostRequest = AssertAndValidationHelper.GetUploadPostRequestForPackage(this, packageFullPath);
yield return uploadPostRequest;
uploadPostRequest = null;
WebTestRequest verifyUploadRequest = new WebTestRequest(UrlHelper.VerifyUploadPageUrl);
yield return verifyUploadRequest;
verifyUploadRequest = null;
WebTestRequest verifyUploadPostRequest = AssertAndValidationHelper.GetVerifyPackagePostRequestForPackage(this, packageId, "1.0.0");
yield return verifyUploadPostRequest;
verifyUploadPostRequest = null;
WebTestRequest verifyEditRequest = AssertAndValidationHelper.GetEditGetRequestForPackage(packageId, "1.0.0");
verifyEditRequest.ExtractValues += new EventHandler<ExtractionEventArgs>(defaultExtractionRule.Extract);
yield return verifyEditRequest;
verifyEditRequest = null;
// TO DO: Post isn't weorking and I need to investigate why. I'll investigate more later, but the current verification is still
// useful in the meantime. [clayco 11/13/2013]
WebTestRequest verifyEditPostRequest = AssertAndValidationHelper.GetEditPackagePostRequest(this, packageId, "1.0.0", description: "This is a new description.");
ValidationRuleFindText newDescriptionValidationRule = AssertAndValidationHelper.GetValidationRuleForFindText(@"This is a new description.");
//ValidationRuleFindText pendingEditValidationRule = AssertAndValidationHelper.GetValidationRuleForFindText(@"An edit is pending for this package version. You are seeing the <em>edited</em> package description now.");
verifyEditPostRequest.ValidateResponse += new EventHandler<ValidationEventArgs>(newDescriptionValidationRule.Validate);
//verifyEditPostRequest.ValidateResponse += new EventHandler<ValidationEventArgs>(pendingEditValidationRule.Validate);
yield return verifyEditPostRequest;
verifyEditPostRequest = null;
}
示例13: GetRequestEnumerator
public override IEnumerator<WebTestRequest> GetRequestEnumerator()
{
// Send a request to home page and check for default home page text.
var homePageRequest = new WebTestRequest(UrlHelper.BaseUrl);
var homePageTextValidationRule = AssertAndValidationHelper.GetValidationRuleForFindText(Constants.HomePageText);
homePageRequest.ValidateResponse += homePageTextValidationRule.Validate;
yield return homePageRequest;
}
示例14: GetRequestEnumerator
public override IEnumerator<WebTestRequest> GetRequestEnumerator()
{
//send a request to home page and check for default home page text.
WebTestRequest homePageRequest = new WebTestRequest(UrlHelper.BaseUrl);
ValidationRuleFindText homePageTextValidationRule = AssertAndValidationHelper.GetValidationRuleForFindText(Constants.HomePageText);
homePageRequest.ValidateResponse += new EventHandler<ValidationEventArgs>(homePageTextValidationRule.Validate);
yield return homePageRequest;
homePageRequest = null;
}
示例15: GetRequestEnumerator
public override IEnumerator<WebTestRequest> GetRequestEnumerator()
{
WebTestRequest uploadPackageRequest = new WebTestRequest(UrlHelper.UploadPageUrl);
uploadPackageRequest.ExpectedResponseUrl = UrlHelper.LogonPageUrlOnPackageUpload;
ValidateHtmlTagInnerText logOnFormValidationRule = AssertAndValidationHelper.GetValidationRuleForHtmlTagInnerText(HtmlTextWriterTag.Label.ToString(), HtmlTextWriterAttribute.For.ToString(), "SignIn_UserNameOrEmail", "Username or Email");
uploadPackageRequest.ValidateResponse += new EventHandler<ValidationEventArgs>(logOnFormValidationRule.Validate);
yield return uploadPackageRequest;
uploadPackageRequest = null;
}