Commit f71a32c4 f71a32c4d99708fc4dc291dec7c1ff66c8a94723 by Christian Gerdes

New Request Plugin: Zip File Upload

Zippar en fil som ska laddas upp precis innan upladdning.
1 parent 8dfa4d7d
......@@ -18,10 +18,44 @@ 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 the file to be uploaded using the files name and adding .zip. Warning, uses %TEMP% for temp storage.")]
public class ZipFileUploadBeforePost : WebTestRequestPlugin
{
String tempDir = null;
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;
tempDir = Path.GetTempPath() + "\\" + Guid.NewGuid().ToString();
Directory.CreateDirectory(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)
{
if (tempDir != null) Directory.Delete(tempDir, true);
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
{
......
......@@ -41,6 +41,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" />
......
<?xml version="1.0" encoding="utf-8"?>
<WebTest Name="WebTest1" Id="c649760b-6dd8-4210-8a6d-3c6596d08668" Owner="" Priority="2147483647" Enabled="True" CssProjectStructure="" CssIteration="" Timeout="0" WorkItemIds="" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010" Description="" CredentialUserName="" CredentialPassword="" PreAuthenticate="True" Proxy="" StopOnError="False" RecordedResultFile="WebTest1.a5a27e2d-474c-43bb-be4d-1b12e85851a0.rec.webtestresult">
<WebTest Name="WebTest1" Id="c649760b-6dd8-4210-8a6d-3c6596d08668" Owner="" Priority="2147483647" Enabled="True" CssProjectStructure="" CssIteration="" Timeout="0" WorkItemIds="" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010" Description="" CredentialUserName="" CredentialPassword="" PreAuthenticate="True" Proxy="default" StopOnError="False" RecordedResultFile="WebTest1.a5a27e2d-474c-43bb-be4d-1b12e85851a0.rec.webtestresult" ResultsLocale="">
<Items>
<Request Method="POST" Version="1.1" Url="http://www.lil.nu/" ThinkTime="0" Timeout="300" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8" ExpectedHttpStatusCode="0" ExpectedResponseUrl="" ReportingName="">
<Headers>
<Header Name="Username" Value="{{DataSource1.Userdata#csv.UserName}}" />
</Headers>
<ExtractionRules>
<ExtractionRule Classname="LIL_VSTT_Plugins.NestedExtractionRule, LIL_VSTT_Plugins, Version=1.0.0.1, Culture=neutral, PublicKeyToken=null" VariableName="TableRowTest" DisplayName="Nested Extraction" Description="(C) Copyright 2011 LIGHTS IN LINE AB&#xD;&#xA;Kombination av två extractions där den andra söker i resultatet av den första.">
<RuleParameters>
<RuleParameter Name="Start1" Value="&lt;table width=&quot;100%&quot;" />
<RuleParameter Name="End1" Value="&lt;/tr&gt;&lt;/table&gt;" />
<RuleParameter Name="Start2" Value="&lt;td id=&quot;start&quot; class=&quot;" />
<RuleParameter Name="End2" Value="&quot; onMouseOver" />
</RuleParameters>
</ExtractionRule>
</ExtractionRules>
<Request Method="POST" Guid="e57c04e5-b0f0-497a-bb41-3d4f42ea39cd" Version="1.1" Url="http://www.lil.nu/" ThinkTime="0" Timeout="300" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8" ExpectedHttpStatusCode="0" ExpectedResponseUrl="" ReportingName="" IgnoreHttpStatusCode="False">
<RequestPlugins>
<RequestPlugin Classname="LIL_VSTT_Plugins.ZipFileUploadBeforePost, LIL_VSTT_Plugins, Version=1.3.0.0, Culture=neutral, PublicKeyToken=null" DisplayName="ZipFileUploadBeforePost" Description="" />
</RequestPlugins>
<FormPostHttpBody>
<FormPostParameter Name="TestParam" Value="LORRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR" RecordedValue="" CorrelationBinding="" UrlEncode="True" />
<FileUploadParameter Name="file" FileName="V:\projekt\2017\idag\data\generated-aug14\generated-files\out\large0\0large.xml" ContentType="application/octet-stream" GenerateUniqueName="False" UseGuids="False" FileUploadName="0large.xml" HtmlEncodeFileName="True" />
<FormPostParameter Name="TestParam" Value="0" RecordedValue="" CorrelationBinding="" UrlEncode="True" />
</FormPostHttpBody>
</Request>
</Items>
......@@ -27,14 +18,4 @@
</Tables>
</DataSource>
</DataSources>
<WebTestPlugins>
<WebTestPlugin Classname="LIL_VSTT_Plugins.UniqueOnce, LIL_VSTT_Plugins, Version=1.0.0.1, Culture=neutral, PublicKeyToken=null" DisplayName="Datasource Unique Once" Description="(C) Copyright 2011 LIGHTS IN LINE AB&#xD;&#xA;OBS! Läs hela! Styr datasource selection till att endast göras en gång per iteration. Du måste ändra i din datasource Access Metod till Do Not Move Automatically! WebTestUserId används för att välja rad. Använder de datasources som finns definerade i webtestet. Använd test mix based on users starting tests samt 0 percent new users.">
<RuleParameters>
<RuleParameter Name="DataSourceName" Value="DataSource1" />
<RuleParameter Name="DataSourceTableName" Value="Userdata#csv" />
<RuleParameter Name="Offset" Value="0" />
</RuleParameters>
</WebTestPlugin>
<WebTestPlugin Classname="LIL_VSTT_Plugins.myPlugin, LIL_VSTT_Plugins, Version=1.0.0.1, Culture=neutral, PublicKeyToken=null" DisplayName="Expect 100 Off" Description="(C) Copyright 2011 LIGHTS IN LINE AB&#xD;&#xA;Stänger av .NET expected-100 headern i posts." />
</WebTestPlugins>
</WebTest>
\ No newline at end of file
......