|
12 | 12 | using System.Threading.Tasks; |
13 | 13 | using Xunit; |
14 | 14 | using ExpectedObjects; |
| 15 | +using System.Security.Authentication; |
15 | 16 |
|
16 | 17 | namespace QAToolKit.Engine.HttpTester.Test |
17 | 18 | { |
@@ -216,5 +217,89 @@ public async Task HttpTesterClientOnlyInstantiation_Exception() |
216 | 217 | await Assert.ThrowsAsync<QAToolKitEngineHttpTesterException>(async () => await client.Start()); |
217 | 218 | } |
218 | 219 | } |
| 220 | + |
| 221 | + [Fact] |
| 222 | + public async Task HttpTesterClientGetWithBodyDisableSSLValidationWithValidCert_Success() |
| 223 | + { |
| 224 | + using (var client = new HttpTesterClient()) |
| 225 | + { |
| 226 | + var response = await client |
| 227 | + .CreateHttpRequest(new Uri("https://qatoolkitapi.azurewebsites.net"), false) |
| 228 | + .WithQueryParams(new Dictionary<string, string>() { { "api-version", "1" } }) |
| 229 | + .WithMethod(HttpMethod.Get) |
| 230 | + .WithPath("/api/bicycles/1") |
| 231 | + .Start(); |
| 232 | + |
| 233 | + var msg = await response.GetResponseBody<Bicycle>(); |
| 234 | + |
| 235 | + var expecterResponse = BicycleFixture.GetFoil().ToExpectedObject(); |
| 236 | + expecterResponse.ShouldEqual(msg); |
| 237 | + |
| 238 | + Assert.True(client.Duration < 2000); |
| 239 | + Assert.True(response.IsSuccessStatusCode); |
| 240 | + Assert.Equal("Scott", msg.Brand); |
| 241 | + } |
| 242 | + } |
| 243 | + |
| 244 | + [Fact] |
| 245 | + public async Task HttpTesterClientGetWithBodyDisableSSLValidationWithInvalidCert_Success() |
| 246 | + { |
| 247 | + using (var client = new HttpTesterClient()) |
| 248 | + { |
| 249 | + var response = await client |
| 250 | + .CreateHttpRequest(new Uri("https://swagger-demo.qatoolkit.io/"), false) |
| 251 | + .WithQueryParams(new Dictionary<string, string>() { { "api-version", "1" } }) |
| 252 | + .WithMethod(HttpMethod.Get) |
| 253 | + .WithPath("/api/bicycles/1") |
| 254 | + .Start(); |
| 255 | + |
| 256 | + var msg = await response.GetResponseBody<Bicycle>(); |
| 257 | + |
| 258 | + var expecterResponse = BicycleFixture.GetFoil().ToExpectedObject(); |
| 259 | + expecterResponse.ShouldEqual(msg); |
| 260 | + |
| 261 | + Assert.True(client.Duration < 2000); |
| 262 | + Assert.True(response.IsSuccessStatusCode); |
| 263 | + Assert.Equal("Scott", msg.Brand); |
| 264 | + } |
| 265 | + } |
| 266 | + |
| 267 | + [Fact] |
| 268 | + public async Task HttpTesterClientGetWithBodyDisableSSLValidationWithHttpUrl_Exception() |
| 269 | + { |
| 270 | + using (var client = new HttpTesterClient()) |
| 271 | + { |
| 272 | + var response = await client |
| 273 | + .CreateHttpRequest(new Uri("http://swagger-demo.qatoolkit.io/"), false) |
| 274 | + .WithQueryParams(new Dictionary<string, string>() { { "api-version", "1" } }) |
| 275 | + .WithMethod(HttpMethod.Get) |
| 276 | + .WithPath("/api/bicycles/1") |
| 277 | + .Start(); |
| 278 | + |
| 279 | + var msg = await response.GetResponseBody<Bicycle>(); |
| 280 | + |
| 281 | + var expecterResponse = BicycleFixture.GetFoil().ToExpectedObject(); |
| 282 | + expecterResponse.ShouldEqual(msg); |
| 283 | + |
| 284 | + Assert.True(client.Duration < 2000); |
| 285 | + Assert.True(response.IsSuccessStatusCode); |
| 286 | + Assert.Equal("Scott", msg.Brand); |
| 287 | + } |
| 288 | + } |
| 289 | + |
| 290 | + [Fact] |
| 291 | + public async Task HttpTesterClientGetWithBodyDisableSSLValidationWithInvalidCertAndUrl2_Exception() |
| 292 | + { |
| 293 | + using (var client = new HttpTesterClient()) |
| 294 | + { |
| 295 | + var response = client |
| 296 | + .CreateHttpRequest(new Uri("http://swagger-demo.qatoolkit.io/"), true) |
| 297 | + .WithQueryParams(new Dictionary<string, string>() { { "api-version", "1" } }) |
| 298 | + .WithMethod(HttpMethod.Get) |
| 299 | + .WithPath("/api/bicycles/1"); |
| 300 | + |
| 301 | + await Assert.ThrowsAsync<HttpRequestException>(async () => await client.Start()); |
| 302 | + } |
| 303 | + } |
219 | 304 | } |
220 | 305 | } |
0 commit comments