New Request Plugin: Zip File Upload
Zippar en fil som ska laddas upp precis innan upladdning.
Showing
3 changed files
with
43 additions
and
26 deletions
... | @@ -18,10 +18,44 @@ using System.ComponentModel; | ... | @@ -18,10 +18,44 @@ using System.ComponentModel; |
18 | using Microsoft.VisualStudio.TestTools.WebTesting.Rules; | 18 | using Microsoft.VisualStudio.TestTools.WebTesting.Rules; |
19 | using System.Text.RegularExpressions; | 19 | using System.Text.RegularExpressions; |
20 | using System.IO; | 20 | using System.IO; |
21 | using System.IO.Compression; | ||
21 | using Microsoft.VisualStudio.TestTools.LoadTesting; | 22 | using Microsoft.VisualStudio.TestTools.LoadTesting; |
22 | 23 | ||
23 | namespace LIL_VSTT_Plugins | 24 | namespace LIL_VSTT_Plugins |
24 | { | 25 | { |
26 | [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.")] | ||
27 | public class ZipFileUploadBeforePost : WebTestRequestPlugin | ||
28 | { | ||
29 | String tempDir = null; | ||
30 | public override void PreRequest(object sender, PreRequestEventArgs e) | ||
31 | { | ||
32 | if (e.Request.Body.GetType() == typeof(FormPostHttpBody)) { | ||
33 | FormPostHttpBody body = (FormPostHttpBody)e.Request.Body; | ||
34 | foreach (FormPostParameter param in body.FormPostParameters) { | ||
35 | if(param.GetType() == typeof(FileUploadParameter)) | ||
36 | { | ||
37 | FileUploadParameter fparam = (FileUploadParameter)param; | ||
38 | tempDir = Path.GetTempPath() + "\\" + Guid.NewGuid().ToString(); | ||
39 | Directory.CreateDirectory(tempDir); | ||
40 | Directory.CreateDirectory(tempDir + @"\ZipDir"); | ||
41 | File.Copy(fparam.FileName, tempDir + @"\ZipDir\" + Path.GetFileName(fparam.FileName)); | ||
42 | ZipFile.CreateFromDirectory(tempDir + @"\ZipDir", tempDir + "\\" + Path.GetFileName(fparam.FileName) + ".zip"); | ||
43 | |||
44 | fparam.FileName = tempDir + "\\" + Path.GetFileName(fparam.FileName) + ".zip"; | ||
45 | fparam.FileUploadName = fparam.FileUploadName + ".zip"; | ||
46 | } | ||
47 | } | ||
48 | } | ||
49 | base.PreRequest(sender, e); | ||
50 | } | ||
51 | |||
52 | public override void PostRequest(object sender, PostRequestEventArgs e) | ||
53 | { | ||
54 | if (tempDir != null) Directory.Delete(tempDir, true); | ||
55 | base.PostRequest(sender, e); | ||
56 | } | ||
57 | } | ||
58 | |||
25 | [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")] | 59 | [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")] |
26 | public class SetRequestThinkTime : WebTestPlugin | 60 | public class SetRequestThinkTime : WebTestPlugin |
27 | { | 61 | { | ... | ... |
... | @@ -41,6 +41,8 @@ | ... | @@ -41,6 +41,8 @@ |
41 | <Reference Include="Microsoft.VisualStudio.QualityTools.WebTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> | 41 | <Reference Include="Microsoft.VisualStudio.QualityTools.WebTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> |
42 | <Reference Include="System" /> | 42 | <Reference Include="System" /> |
43 | <Reference Include="System.Core" /> | 43 | <Reference Include="System.Core" /> |
44 | <Reference Include="System.IO.Compression" /> | ||
45 | <Reference Include="System.IO.Compression.FileSystem" /> | ||
44 | <Reference Include="System.Xml.Linq" /> | 46 | <Reference Include="System.Xml.Linq" /> |
45 | <Reference Include="System.Data.DataSetExtensions" /> | 47 | <Reference Include="System.Data.DataSetExtensions" /> |
46 | <Reference Include="Microsoft.CSharp" /> | 48 | <Reference Include="Microsoft.CSharp" /> | ... | ... |
1 | <?xml version="1.0" encoding="utf-8"?> | 1 | <?xml version="1.0" encoding="utf-8"?> |
2 | <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"> | 2 | <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=""> |
3 | <Items> | 3 | <Items> |
4 | <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=""> | 4 | <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"> |
5 | <Headers> | 5 | <RequestPlugins> |
6 | <Header Name="Username" Value="{{DataSource1.Userdata#csv.UserName}}" /> | 6 | <RequestPlugin Classname="LIL_VSTT_Plugins.ZipFileUploadBeforePost, LIL_VSTT_Plugins, Version=1.3.0.0, Culture=neutral, PublicKeyToken=null" DisplayName="ZipFileUploadBeforePost" Description="" /> |
7 | </Headers> | 7 | </RequestPlugins> |
8 | <ExtractionRules> | ||
9 | <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
Kombination av två extractions där den andra söker i resultatet av den första."> | ||
10 | <RuleParameters> | ||
11 | <RuleParameter Name="Start1" Value="<table width="100%"" /> | ||
12 | <RuleParameter Name="End1" Value="</tr></table>" /> | ||
13 | <RuleParameter Name="Start2" Value="<td id="start" class="" /> | ||
14 | <RuleParameter Name="End2" Value="" onMouseOver" /> | ||
15 | </RuleParameters> | ||
16 | </ExtractionRule> | ||
17 | </ExtractionRules> | ||
18 | <FormPostHttpBody> | 8 | <FormPostHttpBody> |
19 | <FormPostParameter Name="TestParam" Value="LORRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR" RecordedValue="" CorrelationBinding="" UrlEncode="True" /> | 9 | <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" /> |
10 | <FormPostParameter Name="TestParam" Value="0" RecordedValue="" CorrelationBinding="" UrlEncode="True" /> | ||
20 | </FormPostHttpBody> | 11 | </FormPostHttpBody> |
21 | </Request> | 12 | </Request> |
22 | </Items> | 13 | </Items> |
... | @@ -27,14 +18,4 @@ | ... | @@ -27,14 +18,4 @@ |
27 | </Tables> | 18 | </Tables> |
28 | </DataSource> | 19 | </DataSource> |
29 | </DataSources> | 20 | </DataSources> |
30 | <WebTestPlugins> | ||
31 | <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
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."> | ||
32 | <RuleParameters> | ||
33 | <RuleParameter Name="DataSourceName" Value="DataSource1" /> | ||
34 | <RuleParameter Name="DataSourceTableName" Value="Userdata#csv" /> | ||
35 | <RuleParameter Name="Offset" Value="0" /> | ||
36 | </RuleParameters> | ||
37 | </WebTestPlugin> | ||
38 | <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
Stänger av .NET expected-100 headern i posts." /> | ||
39 | </WebTestPlugins> | ||
40 | </WebTest> | 21 | </WebTest> |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or sign in to post a comment