Commit 60f30298 60f3029879f5e8cb6d697300a0ab537a4fb998d5 by Mick Smith

Senaste version från LIL-GIT 2017-09-12. MICK

git-tfs-id: [https://tfs.rsv.se/tfs/LoadTestCollection]$/VSTT-Plugins;C1190
1 parent 61003c77
......@@ -18,10 +18,46 @@ using System.ComponentModel;
using Microsoft.VisualStudio.TestTools.WebTesting.Rules;
using System.Text.RegularExpressions;
using System.IO;
using System.IO.Compression;
using Microsoft.VisualStudio.TestTools.LoadTesting;
namespace LIL_VSTT_Plugins
{
[DisplayName("Zip File Upload"), Description("Creates an ZIP archive of each of the files to be uploaded using the files name and adding .zip. Warning, uses %TEMP% for temp storage.")]
public class ZipFileUploadBeforePost : WebTestRequestPlugin
{
Queue<String> deleteDirs = new Queue<string>();
public override void PreRequest(object sender, PreRequestEventArgs e)
{
if (e.Request.Body.GetType() == typeof(FormPostHttpBody)) {
FormPostHttpBody body = (FormPostHttpBody)e.Request.Body;
foreach (FormPostParameter param in body.FormPostParameters) {
if(param.GetType() == typeof(FileUploadParameter))
{
FileUploadParameter fparam = (FileUploadParameter)param;
String tempDir = Path.GetTempPath() + "\\" + Guid.NewGuid().ToString();
Directory.CreateDirectory(tempDir);
deleteDirs.Enqueue(tempDir);
Directory.CreateDirectory(tempDir + @"\ZipDir");
File.Copy(fparam.FileName, tempDir + @"\ZipDir\" + Path.GetFileName(fparam.FileName));
ZipFile.CreateFromDirectory(tempDir + @"\ZipDir", tempDir + "\\" + Path.GetFileName(fparam.FileName) + ".zip");
fparam.FileName = tempDir + "\\" + Path.GetFileName(fparam.FileName) + ".zip";
fparam.FileUploadName = fparam.FileUploadName + ".zip";
}
}
}
base.PreRequest(sender, e);
}
public override void PostRequest(object sender, PostRequestEventArgs e)
{
foreach (String dir in deleteDirs) Directory.Delete(dir, true);
deleteDirs.Clear();
base.PostRequest(sender, e);
}
}
[DisplayName("Set Request Think Time"), Description("Changes the thinktime on requests with a set thinktime over 0 to the value of the ThinkTime context parameter")]
public class SetRequestThinkTime : WebTestPlugin
{
......@@ -208,6 +244,9 @@ namespace LIL_VSTT_Plugins
[DisplayName("File Name"), Description("The file name to use for logging")]
public String Filename { get; set; }
[DisplayName("Autogenerate File Name"), Description("Automatically generate a filename using the test name and user id from the load test")]
public bool autoFilename { get; set; }
[DisplayName("Write header"), DefaultValue(false), Description("Writes the parameter names as a header. Will write a new header for each user (dont use in loadtest)")]
public bool useHeader { get; set; }
......@@ -221,6 +260,11 @@ namespace LIL_VSTT_Plugins
public override void PostWebTest(object sender, PostWebTestEventArgs e)
{
String completeFileName = Filename + e.WebTest.Context.WebTestUserId + ".log";
if (autoFilename)
{
completeFileName = e.WebTest.Name + e.WebTest.Context.WebTestUserId + ".log";
}
if ((e.WebTest.Outcome == Outcome.Pass && logPassed) || (e.WebTest.Outcome == Outcome.Fail && logFailed)) {
string row = "";
string hrow = "";
......@@ -240,10 +284,10 @@ namespace LIL_VSTT_Plugins
}
if (header && useHeader)
{
File.AppendAllText(Filename + e.WebTest.Context.WebTestUserId + ".log", hrow + "\r\n");
File.AppendAllText(completeFileName, hrow + "\r\n");
header = false;
}
File.AppendAllText(Filename + e.WebTest.Context.WebTestUserId + ".log", row + "\r\n");
File.AppendAllText(completeFileName, row + "\r\n");
base.PostWebTest(sender, e);
}
}
......
......@@ -13,6 +13,10 @@
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
......@@ -41,6 +45,8 @@
<Reference Include="Microsoft.VisualStudio.QualityTools.WebTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
......
""
{
"FILE_VERSION" = "9237"
"ENLISTMENT_CHOICE" = "NEVER"
"PROJECT_FILE_RELATIVE_PATH" = ""
"NUMBER_OF_EXCLUDED_FILES" = "0"
"ORIGINAL_PROJECT_FILE_PATH" = ""
"NUMBER_OF_NESTED_PROJECTS" = "0"
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
}
......@@ -52,6 +52,31 @@ namespace LIL_VSTT_Plugins
}
/// <summary>
/// LoadTest Context Copy
/// </summary>
[DisplayName("Personnummer Generator")]
[Description("(C) Copyright 2017 LIGHTS IN LINE AB\r\nGenererar personnummer och sätter dem som parameter till testernas context.")]
public class LoadTestPnumGen : ILoadTestPlugin
{
//store the load test object.
LoadTest mLoadTest;
public void Initialize(LoadTest loadTest)
{
mLoadTest = loadTest;
//connect to the TestStarting event.
mLoadTest.TestStarting += new EventHandler<TestStartingEventArgs>(mLoadTest_TestStarting);
}
void mLoadTest_TestStarting(object sender, TestStartingEventArgs e)
{
//TODO
}
}
/// <summary>
/// Service Manager Plugin
/// </summary>
[DisplayName("Service Manager Config")]
......@@ -457,6 +482,7 @@ namespace LIL_VSTT_Plugins
string input = null;
int lineNum = 0;
int dataNum = 0;
char[] trim = { ' ', '\x00', '\t', '\x20' };
while ((input = re.ReadLine()) != null)
{
// Ignore blank lines and empty lines (just whitespace) or lines with only blank/empty/whitespace columns
......@@ -466,7 +492,7 @@ namespace LIL_VSTT_Plugins
if (lineNum == 1 && myHasColName == true)
{
// First line is column names
myColNames = input.TrimEnd();
myColNames = input.TrimEnd(trim);
}
else
{
......@@ -477,13 +503,13 @@ namespace LIL_VSTT_Plugins
else ifAgentId = dataNum + 1;
if (ifAgentId == agentId)
{
myParams.Add(input.TrimEnd());
myParams.Add(input.TrimEnd(trim));
}
dataNum++;
}
else
{
myParams.Add(input.TrimEnd());
myParams.Add(input.TrimEnd(trim));
}
}
}
......