User:Nikkistart999999/sandbox

This is just a test // C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.VisualStudio.QualityTools.WebTestFramework.dll
 * 1) region Assembly Microsoft.VisualStudio.QualityTools.WebTestFramework.dll, v10.0.0.0
 * 1) endregion

using System;

namespace Microsoft.VisualStudio.TestTools.WebTesting {   [Serializable] public class DataSource : ICloneable {       public const string CsvProvider = "Microsoft.VisualStudio.TestTools.DataSource.CSV"; public const string XmlProvider = "Microsoft.VisualStudio.TestTools.DataSource.XML";

public DataSource;

public string Connection { get; } public string Name { get; set; } public string Provider { get; } public DataSourceTableCollection Tables { get; }

public object Clone; public void SetConnection(string provider, string connection); public void SetConnection(string provider, string connection, string connectionDisplayValue); } } ---

using System; using System.Collections.Generic; using System.Configuration; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Resources; using Microsoft.VisualStudio.TestTools.WebTesting; using Microsoft.VisualStudio.TestTools.LoadTesting;

namespace TestPlugin {   public class TestStartPlugIn:ILoadTestPlugin {       public void Initialize(LoadTest loadTest) {           var appsettings = (AppSettingsSection)Utility.GetConfigSection("appSettings"); var connectionstrings = (ConnectionStringsSection)Utility.GetConfigSection("connectionStrings"); foreach (var key in appsettings.Settings.AllKeys) {               if (loadTest.Context.ContainsKey(key)) loadTest.Context[key] = appsettings.Settings[key].Value; else loadTest.Context.Add(key, appsettings.Settings[key].Value); }           foreach (ConnectionStringSettings conn in connectionstrings.ConnectionStrings) {               if (loadTest.Context.ContainsKey(conn.Name)) loadTest.Context[conn.Name] = conn.ConnectionString; else loadTest.Context.Add(conn.Name, conn.ConnectionString); }             }    } } - Request verification token: Add form parameters - value - $HIDDEN1.__RequestVerificationToken $HIDDEN1.RememberMe

query string parameters - ajax name and ajax value

Extract hidden fields

--

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Data.SqlClient; using System.Data; using Microsoft.VisualStudio.TestTools.WebTesting; using RetryLogic; using System.Security.Cryptography;

namespace  TestPlugin {   public class GetUserCredentialsPlugin : WebTestRequestPlugin {       public override void PreRequestDataBinding(object sender, PreRequestDataBindingEventArgs e)        { int stage; if (e.WebTest.Context.ContainsKey("LoginStage")) stage = Int32.Parse(e.WebTest.Context["LoginStage"].ToString); else stage = Int32.Parse(e.WebTest.Context["Stage"].ToString);

var connectionstring = Utility.GetConnectionString(e.WebTest, "TestUsers");

// Connect to the master database and create the sample database RetryableAction.Execute( =>           {                using (SqlConnection conn = new SqlConnection(connectionstring))                {                    using (SqlCommand command = conn.CreateCommand)                    {                        int maxNum;                        maxNum = (int)e.WebTest.Context["MaxUsers"];                        switch (stage)                        {                            case 3:                                command.CommandText = "Prc_GetUserFromChapter5Users";                                //maxNum = (int)e.WebTest.Context["MaxChapter5Users"];                                break;

default: command.CommandText = "Prc_GetUserFromGeneratedUsers"; //maxNum = (int)e.WebTest.Context["MaxGeneratedUsers"]; break; }

//Execute the appropriate stored procedure command.CommandType = CommandType.StoredProcedure;

//bind parameter command.Parameters.Add("@maxid", SqlDbType.Int); var randInt = Randomise(maxNum); command.Parameters[0].Value = randInt;

//Open connection conn.Open;

//Execute the stored procedure SqlDataReader reader = command.ExecuteReader; if (reader.Read) {                           if (e.WebTest.Context.ContainsKey("Username")) e.WebTest.Context["Username"] = reader[0].ToString; else e.WebTest.Context.Add("Username", reader[0].ToString); if (e.WebTest.Context.ContainsKey("Password")) e.WebTest.Context["Password"] = reader[1].ToString; else e.WebTest.Context.Add("Password", reader[1].ToString);

LogActivity.LogSQL(String.Format("Executed {0}", command.CommandText)); }                       else {                           LogActivity.LogError(string.Format("ID not found from {0} with {1}", command.CommandText, command.Parameters[0].Value)); }

}               }            }, ThrowIf.RetryCountIs(3), SleepFor.RandomExponential(250), (ex) => {               LogActivity.LogError(ex.Message); });

base.PreRequestDataBinding(sender, e); }       private int Randomise (int upperLimit) {           byte[] byt = new byte[4]; RNGCryptoServiceProvider rngCrypto = new RNGCryptoServiceProvider; rngCrypto.GetBytes(byt); int randomNumber = BitConverter.ToInt32(byt, 0); return Math.Abs(randomNumber % upperLimit );

}   } }

--

          