Skip to content

Commit 1adf1d1

Browse files
committed
custome xception, HTTP DELETE test, cleanup
1 parent ba879f8 commit 1adf1d1

13 files changed

+174
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ in the sample code above. Check the [QAToolKit.Source.Swagger](https://github.co
137137

138138
## TO-DO
139139

140-
N/A
140+
- Currently tested for GET, POST, PUT and DELETE HTTP methods. Need to extend support.
141141

142142
## License
143143

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
[
2+
{
3+
"BasePath": "https://qatoolkitapi.azurewebsites.net/",
4+
"Path": "/api/bicycles/{id}",
5+
"OperationId": "DeleteBike",
6+
"Method": {
7+
"Method": "DELETE"
8+
},
9+
"Summary": "Delete a bike",
10+
"Description": "Delete a bike by id",
11+
"Tags": [
12+
"Public"
13+
],
14+
"Parameters": [
15+
{
16+
"Name": "id",
17+
"Type": "integer",
18+
"Nullable": false,
19+
"Value": null,
20+
"Required": true,
21+
"Location": 1
22+
},
23+
{
24+
"Name": "api-version",
25+
"Type": "string",
26+
"Nullable": false,
27+
"Value": "1",
28+
"Required": false,
29+
"Location": 2
30+
},
31+
{
32+
"Name": "X-version",
33+
"Type": "string",
34+
"Nullable": false,
35+
"Value": null,
36+
"Required": false,
37+
"Location": 3
38+
}
39+
],
40+
"RequestBodies": [],
41+
"Responses": [
42+
{
43+
"StatusCode": 400,
44+
"Type": 2,
45+
"Properties": [
46+
{
47+
"Name": "statusCode",
48+
"Description": null,
49+
"Format": "int32",
50+
"Type": "integer",
51+
"Value": null,
52+
"Required": false,
53+
"Properties": null
54+
},
55+
{
56+
"Name": "statusDescription",
57+
"Description": null,
58+
"Format": null,
59+
"Type": "string",
60+
"Value": null,
61+
"Required": false,
62+
"Properties": null
63+
},
64+
{
65+
"Name": "message",
66+
"Description": null,
67+
"Format": null,
68+
"Type": "string",
69+
"Value": null,
70+
"Required": false,
71+
"Properties": null
72+
},
73+
{
74+
"Name": "errorCode",
75+
"Description": null,
76+
"Format": "int32",
77+
"Type": "integer",
78+
"Value": null,
79+
"Required": false,
80+
"Properties": null
81+
}
82+
]
83+
},
84+
{
85+
"StatusCode": 204,
86+
"Type": 1,
87+
"Properties": null
88+
}
89+
],
90+
"TestTypes": [],
91+
"AuthenticationTypes": []
92+
}
93+
]

src/QAToolKit.Engine.Bombardier.Test/BombardierTestsGeneratorTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,5 +538,31 @@ public async Task GenerateBombardierTestPutUpdateBikeIntValueTest_Successfull()
538538
Assert.Equal(HttpMethod.Put, bombardierTests.FirstOrDefault().Method);
539539
Assert.Equal("https://qatoolkitapi.azurewebsites.net/api/bicycles/1?api-version=1", bombardierTests.FirstOrDefault().Url.ToString());
540540
}
541+
542+
[Fact]
543+
public async Task GenerateBombardierTestDeleteBikeTest_Successfull()
544+
{
545+
546+
var bombardierTestsGenerator = new BombardierTestsGenerator(options =>
547+
{
548+
options.AddReplacementValues(new ReplacementValue[] {
549+
new ReplacementValue(){
550+
Key = "id",
551+
Value = 1
552+
}
553+
});
554+
});
555+
556+
var content = File.ReadAllText("Assets/DeleteBike.json");
557+
var httpRequest = JsonConvert.DeserializeObject<IList<HttpRequest>>(content);
558+
559+
var bombardierTests = await bombardierTestsGenerator.Generate(httpRequest);
560+
561+
Assert.NotNull(bombardierTests);
562+
Assert.Single(bombardierTests);
563+
Assert.Contains($@" -m DELETE https://qatoolkitapi.azurewebsites.net/api/bicycles/1?api-version=1 -c 3 --http2 --timeout=30s --duration=5s", bombardierTests.FirstOrDefault().Command);
564+
Assert.Equal(HttpMethod.Delete, bombardierTests.FirstOrDefault().Method);
565+
Assert.Equal("https://qatoolkitapi.azurewebsites.net/api/bicycles/1?api-version=1", bombardierTests.FirstOrDefault().Url.ToString());
566+
}
541567
}
542568
}

src/QAToolKit.Engine.Bombardier.Test/QAToolKit.Engine.Bombardier.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
<None Update="Assets\addPet.json">
3333
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
3434
</None>
35+
<None Update="Assets\DeleteBike.json">
36+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
37+
</None>
3538
<None Update="Assets\GetAllBikes.json">
3639
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
3740
</None>

src/QAToolKit.Engine.Bombardier/BombardierGeneratorOptions.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using QAToolKit.Core.Models;
2+
using System;
23
using System.Collections.Generic;
34
using System.Runtime.CompilerServices;
45

@@ -74,6 +75,9 @@ public class BombardierGeneratorOptions
7475
/// <returns></returns>
7576
public BombardierGeneratorOptions AddReplacementValues(ReplacementValue[] replacementValues)
7677
{
78+
if (replacementValues == null)
79+
throw new ArgumentException(nameof(replacementValues));
80+
7781
ReplacementValues = replacementValues;
7882
return this;
7983
}
@@ -86,6 +90,11 @@ public BombardierGeneratorOptions AddReplacementValues(ReplacementValue[] replac
8690
/// <returns></returns>
8791
public BombardierGeneratorOptions AddOAuth2Token(string token, AuthenticationType authenticationType)
8892
{
93+
if (string.IsNullOrEmpty(token))
94+
throw new ArgumentException(nameof(token));
95+
if (authenticationType == null)
96+
throw new ArgumentException(nameof(authenticationType));
97+
8998
AccessTokens.Add(authenticationType, token);
9099
return this;
91100
}
@@ -97,6 +106,9 @@ public BombardierGeneratorOptions AddOAuth2Token(string token, AuthenticationTyp
97106
/// <returns></returns>
98107
public BombardierGeneratorOptions AddApiKey(string apiKey)
99108
{
109+
if (string.IsNullOrEmpty(apiKey))
110+
throw new ArgumentException(nameof(apiKey));
111+
100112
ApiKey = apiKey;
101113
return this;
102114
}
@@ -109,6 +121,11 @@ public BombardierGeneratorOptions AddApiKey(string apiKey)
109121
/// <returns></returns>
110122
public BombardierGeneratorOptions AddBasicAuthentication(string userName, string password)
111123
{
124+
if (string.IsNullOrEmpty(userName))
125+
throw new ArgumentException(nameof(userName));
126+
if (string.IsNullOrEmpty(password))
127+
throw new ArgumentException(nameof(password));
128+
112129
UserName = userName;
113130
Password = password;
114131
return this;

src/QAToolKit.Engine.Bombardier/BombardierTestsGenerator.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using QAToolKit.Core.Interfaces;
22
using QAToolKit.Core.Models;
33
using QAToolKit.Engine.Bombardier.Helpers;
4+
using QAToolKit.Engine.Bombardier.Models;
45
using System;
56
using System.Collections.Generic;
67
using System.IO;
@@ -34,6 +35,9 @@ public BombardierTestsGenerator(Action<BombardierGeneratorOptions> options = nul
3435
/// <param name="restRequests"></param>
3536
public async Task<IEnumerable<BombardierTest>> Generate(IList<HttpRequest> restRequests)
3637
{
38+
if (restRequests == null)
39+
throw new ArgumentNullException(nameof(restRequests));
40+
3741
var bombardierTests = new List<BombardierTest>();
3842
var scriptBuilder = new StringBuilder();
3943

src/QAToolKit.Engine.Bombardier/BombardierTestsRunner.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using QAToolKit.Core.Helpers;
2+
using QAToolKit.Engine.Bombardier.Models;
23
using System;
34
using System.Collections.Generic;
45
using System.Diagnostics;
@@ -47,7 +48,7 @@ public async Task<IList<BombardierResult>> Run()
4748

4849
foreach (var test in _bombardierTests)
4950
{
50-
bombardierResult.Add(await Run(test.Command));
51+
bombardierResult.Add(await Run(test.Command).ConfigureAwait(false));
5152
}
5253

5354
return bombardierResult;
@@ -80,7 +81,7 @@ private async Task<BombardierResult> Run(string testCommand)
8081

8182
while (!process.StandardOutput.EndOfStream)
8283
{
83-
bombardrierOutput.AppendLine(await process.StandardOutput.ReadLineAsync());
84+
bombardrierOutput.AppendLine(await process.StandardOutput.ReadLineAsync().ConfigureAwait(false));
8485
}
8586

8687
process.WaitForExit();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Runtime.Serialization;
3+
4+
namespace QAToolKit.Engine.Bombardier.Exceptions
5+
{
6+
internal class QAToolKitBombardierException : Exception
7+
{
8+
public QAToolKitBombardierException(string message) : base(message)
9+
{
10+
}
11+
12+
public QAToolKitBombardierException(string message, Exception innerException) : base(message, innerException)
13+
{
14+
}
15+
16+
protected QAToolKitBombardierException(SerializationInfo info, StreamingContext context) : base(info, context)
17+
{
18+
}
19+
}
20+
}

src/QAToolKit.Engine.Bombardier/Helpers/AuthorizationHeaderHelper.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using QAToolKit.Core.Models;
2+
using QAToolKit.Engine.Bombardier.Exceptions;
23
using System;
34
using System.Collections.Generic;
45
using System.Linq;
@@ -63,7 +64,7 @@ private static string GetOauth2AuthenticationHeader(Dictionary<AuthenticationTyp
6364
}
6465
else
6566
{
66-
throw new Exception($"One of the access token is missing (AuthenticationType {authenticationType.Value()} required).");
67+
throw new QAToolKitBombardierException($"One of the access token is missing (AuthenticationType {authenticationType.Value()} required).");
6768
}
6869

6970
return authHeader;
@@ -81,7 +82,7 @@ private static string GetBasicAuthenticationHeader(BombardierGeneratorOptions bo
8182
}
8283
else
8384
{
84-
throw new Exception($"User name and password for basic authentication are missing and are required).");
85+
throw new QAToolKitBombardierException($"User name and password for basic authentication are missing and are required).");
8586
}
8687

8788
return authHeader;
@@ -97,7 +98,7 @@ private static string GetApiKeyAuthenticationHeader(BombardierGeneratorOptions b
9798
}
9899
else
99100
{
100-
throw new Exception($"Api Key is missing and is required.");
101+
throw new QAToolKitBombardierException($"Api Key is missing and is required.");
101102
}
102103

103104
return authHeader;

src/QAToolKit.Engine.Bombardier/Helpers/ContentTypeHeaderHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ internal static string GenerateContentTypeHeader(HttpRequest request, ContentTyp
3232
}
3333
else
3434
{
35-
throw new Exception($"Content type header '{useContentType}' not found in the HttpRequest.");
35+
return String.Empty;
3636
}
3737
}
3838
}

0 commit comments

Comments
 (0)