Senaste version från LIL-GIT 2017-09-12. MICK
git-tfs-id: [https://tfs.rsv.se/tfs/LoadTestCollection]$/VSTT-Plugins;C1190
Showing
5 changed files
with
91 additions
and
5 deletions
| ... | @@ -18,10 +18,46 @@ using System.ComponentModel; | ... | @@ -18,10 +18,46 @@ 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 each of the files to be uploaded using the files name and adding .zip. Warning, uses %TEMP% for temp storage.")] | ||
| 27 | public class ZipFileUploadBeforePost : WebTestRequestPlugin | ||
| 28 | { | ||
| 29 | Queue<String> deleteDirs = new Queue<string>(); | ||
| 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 | String tempDir = Path.GetTempPath() + "\\" + Guid.NewGuid().ToString(); | ||
| 39 | Directory.CreateDirectory(tempDir); | ||
| 40 | deleteDirs.Enqueue(tempDir); | ||
| 41 | Directory.CreateDirectory(tempDir + @"\ZipDir"); | ||
| 42 | File.Copy(fparam.FileName, tempDir + @"\ZipDir\" + Path.GetFileName(fparam.FileName)); | ||
| 43 | ZipFile.CreateFromDirectory(tempDir + @"\ZipDir", tempDir + "\\" + Path.GetFileName(fparam.FileName) + ".zip"); | ||
| 44 | |||
| 45 | fparam.FileName = tempDir + "\\" + Path.GetFileName(fparam.FileName) + ".zip"; | ||
| 46 | fparam.FileUploadName = fparam.FileUploadName + ".zip"; | ||
| 47 | } | ||
| 48 | } | ||
| 49 | } | ||
| 50 | base.PreRequest(sender, e); | ||
| 51 | } | ||
| 52 | |||
| 53 | public override void PostRequest(object sender, PostRequestEventArgs e) | ||
| 54 | { | ||
| 55 | foreach (String dir in deleteDirs) Directory.Delete(dir, true); | ||
| 56 | deleteDirs.Clear(); | ||
| 57 | base.PostRequest(sender, e); | ||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 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")] | 61 | [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 | 62 | public class SetRequestThinkTime : WebTestPlugin |
| 27 | { | 63 | { |
| ... | @@ -208,6 +244,9 @@ namespace LIL_VSTT_Plugins | ... | @@ -208,6 +244,9 @@ namespace LIL_VSTT_Plugins |
| 208 | [DisplayName("File Name"), Description("The file name to use for logging")] | 244 | [DisplayName("File Name"), Description("The file name to use for logging")] |
| 209 | public String Filename { get; set; } | 245 | public String Filename { get; set; } |
| 210 | 246 | ||
| 247 | [DisplayName("Autogenerate File Name"), Description("Automatically generate a filename using the test name and user id from the load test")] | ||
| 248 | public bool autoFilename { get; set; } | ||
| 249 | |||
| 211 | [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)")] | 250 | [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)")] |
| 212 | public bool useHeader { get; set; } | 251 | public bool useHeader { get; set; } |
| 213 | 252 | ||
| ... | @@ -221,6 +260,11 @@ namespace LIL_VSTT_Plugins | ... | @@ -221,6 +260,11 @@ namespace LIL_VSTT_Plugins |
| 221 | 260 | ||
| 222 | public override void PostWebTest(object sender, PostWebTestEventArgs e) | 261 | public override void PostWebTest(object sender, PostWebTestEventArgs e) |
| 223 | { | 262 | { |
| 263 | String completeFileName = Filename + e.WebTest.Context.WebTestUserId + ".log"; | ||
| 264 | if (autoFilename) | ||
| 265 | { | ||
| 266 | completeFileName = e.WebTest.Name + e.WebTest.Context.WebTestUserId + ".log"; | ||
| 267 | } | ||
| 224 | if ((e.WebTest.Outcome == Outcome.Pass && logPassed) || (e.WebTest.Outcome == Outcome.Fail && logFailed)) { | 268 | if ((e.WebTest.Outcome == Outcome.Pass && logPassed) || (e.WebTest.Outcome == Outcome.Fail && logFailed)) { |
| 225 | string row = ""; | 269 | string row = ""; |
| 226 | string hrow = ""; | 270 | string hrow = ""; |
| ... | @@ -240,10 +284,10 @@ namespace LIL_VSTT_Plugins | ... | @@ -240,10 +284,10 @@ namespace LIL_VSTT_Plugins |
| 240 | } | 284 | } |
| 241 | if (header && useHeader) | 285 | if (header && useHeader) |
| 242 | { | 286 | { |
| 243 | File.AppendAllText(Filename + e.WebTest.Context.WebTestUserId + ".log", hrow + "\r\n"); | 287 | File.AppendAllText(completeFileName, hrow + "\r\n"); |
| 244 | header = false; | 288 | header = false; |
| 245 | } | 289 | } |
| 246 | File.AppendAllText(Filename + e.WebTest.Context.WebTestUserId + ".log", row + "\r\n"); | 290 | File.AppendAllText(completeFileName, row + "\r\n"); |
| 247 | base.PostWebTest(sender, e); | 291 | base.PostWebTest(sender, e); |
| 248 | } | 292 | } |
| 249 | } | 293 | } | ... | ... |
| ... | @@ -13,6 +13,10 @@ | ... | @@ -13,6 +13,10 @@ |
| 13 | <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | 13 | <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> |
| 14 | <FileAlignment>512</FileAlignment> | 14 | <FileAlignment>512</FileAlignment> |
| 15 | <TargetFrameworkProfile /> | 15 | <TargetFrameworkProfile /> |
| 16 | <SccProjectName>SAK</SccProjectName> | ||
| 17 | <SccLocalPath>SAK</SccLocalPath> | ||
| 18 | <SccAuxPath>SAK</SccAuxPath> | ||
| 19 | <SccProvider>SAK</SccProvider> | ||
| 16 | </PropertyGroup> | 20 | </PropertyGroup> |
| 17 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | 21 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
| 18 | <DebugSymbols>true</DebugSymbols> | 22 | <DebugSymbols>true</DebugSymbols> |
| ... | @@ -41,6 +45,8 @@ | ... | @@ -41,6 +45,8 @@ |
| 41 | <Reference Include="Microsoft.VisualStudio.QualityTools.WebTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> | 45 | <Reference Include="Microsoft.VisualStudio.QualityTools.WebTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> |
| 42 | <Reference Include="System" /> | 46 | <Reference Include="System" /> |
| 43 | <Reference Include="System.Core" /> | 47 | <Reference Include="System.Core" /> |
| 48 | <Reference Include="System.IO.Compression" /> | ||
| 49 | <Reference Include="System.IO.Compression.FileSystem" /> | ||
| 44 | <Reference Include="System.Xml.Linq" /> | 50 | <Reference Include="System.Xml.Linq" /> |
| 45 | <Reference Include="System.Data.DataSetExtensions" /> | 51 | <Reference Include="System.Data.DataSetExtensions" /> |
| 46 | <Reference Include="Microsoft.CSharp" /> | 52 | <Reference Include="Microsoft.CSharp" /> | ... | ... |
| ... | @@ -52,6 +52,31 @@ namespace LIL_VSTT_Plugins | ... | @@ -52,6 +52,31 @@ namespace LIL_VSTT_Plugins |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | /// <summary> | 54 | /// <summary> |
| 55 | /// LoadTest Context Copy | ||
| 56 | /// </summary> | ||
| 57 | [DisplayName("Personnummer Generator")] | ||
| 58 | [Description("(C) Copyright 2017 LIGHTS IN LINE AB\r\nGenererar personnummer och sätter dem som parameter till testernas context.")] | ||
| 59 | public class LoadTestPnumGen : ILoadTestPlugin | ||
| 60 | { | ||
| 61 | //store the load test object. | ||
| 62 | LoadTest mLoadTest; | ||
| 63 | |||
| 64 | public void Initialize(LoadTest loadTest) | ||
| 65 | { | ||
| 66 | mLoadTest = loadTest; | ||
| 67 | |||
| 68 | //connect to the TestStarting event. | ||
| 69 | mLoadTest.TestStarting += new EventHandler<TestStartingEventArgs>(mLoadTest_TestStarting); | ||
| 70 | } | ||
| 71 | |||
| 72 | |||
| 73 | void mLoadTest_TestStarting(object sender, TestStartingEventArgs e) | ||
| 74 | { | ||
| 75 | //TODO | ||
| 76 | } | ||
| 77 | } | ||
| 78 | |||
| 79 | /// <summary> | ||
| 55 | /// Service Manager Plugin | 80 | /// Service Manager Plugin |
| 56 | /// </summary> | 81 | /// </summary> |
| 57 | [DisplayName("Service Manager Config")] | 82 | [DisplayName("Service Manager Config")] |
| ... | @@ -457,6 +482,7 @@ namespace LIL_VSTT_Plugins | ... | @@ -457,6 +482,7 @@ namespace LIL_VSTT_Plugins |
| 457 | string input = null; | 482 | string input = null; |
| 458 | int lineNum = 0; | 483 | int lineNum = 0; |
| 459 | int dataNum = 0; | 484 | int dataNum = 0; |
| 485 | char[] trim = { ' ', '\x00', '\t', '\x20' }; | ||
| 460 | while ((input = re.ReadLine()) != null) | 486 | while ((input = re.ReadLine()) != null) |
| 461 | { | 487 | { |
| 462 | // Ignore blank lines and empty lines (just whitespace) or lines with only blank/empty/whitespace columns | 488 | // Ignore blank lines and empty lines (just whitespace) or lines with only blank/empty/whitespace columns |
| ... | @@ -466,7 +492,7 @@ namespace LIL_VSTT_Plugins | ... | @@ -466,7 +492,7 @@ namespace LIL_VSTT_Plugins |
| 466 | if (lineNum == 1 && myHasColName == true) | 492 | if (lineNum == 1 && myHasColName == true) |
| 467 | { | 493 | { |
| 468 | // First line is column names | 494 | // First line is column names |
| 469 | myColNames = input.TrimEnd(); | 495 | myColNames = input.TrimEnd(trim); |
| 470 | } | 496 | } |
| 471 | else | 497 | else |
| 472 | { | 498 | { |
| ... | @@ -477,13 +503,13 @@ namespace LIL_VSTT_Plugins | ... | @@ -477,13 +503,13 @@ namespace LIL_VSTT_Plugins |
| 477 | else ifAgentId = dataNum + 1; | 503 | else ifAgentId = dataNum + 1; |
| 478 | if (ifAgentId == agentId) | 504 | if (ifAgentId == agentId) |
| 479 | { | 505 | { |
| 480 | myParams.Add(input.TrimEnd()); | 506 | myParams.Add(input.TrimEnd(trim)); |
| 481 | } | 507 | } |
| 482 | dataNum++; | 508 | dataNum++; |
| 483 | } | 509 | } |
| 484 | else | 510 | else |
| 485 | { | 511 | { |
| 486 | myParams.Add(input.TrimEnd()); | 512 | myParams.Add(input.TrimEnd(trim)); |
| 487 | } | 513 | } |
| 488 | } | 514 | } |
| 489 | } | 515 | } | ... | ... |
This diff is collapsed.
Click to expand it.
-
Please register or sign in to post a comment