Skip to content

Commit a7261cd

Browse files
committed
small bug fixes and test upgrade
1 parent ecbbc96 commit a7261cd

File tree

11 files changed

+352
-10
lines changed

11 files changed

+352
-10
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>0.1.1</Version>
3+
<Version>0.1.5</Version>
44
</PropertyGroup>
55
</Project>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using QAToolKit.Core.Models;
2+
using System.Collections.Generic;
3+
using System.Net;
4+
5+
namespace QAToolKit.Source.Swagger.Test.Fixtures.BicycleApi
6+
{
7+
public static class BicycleResponse400
8+
{
9+
public static Response Get()
10+
{
11+
return new Response()
12+
{
13+
StatusCode = HttpStatusCode.BadRequest,
14+
Type = ResponseType.Object,
15+
Properties = new List<Property>()
16+
{
17+
new Property() {
18+
Name = "statusCode",
19+
Description = null,
20+
Format = "int32",
21+
Required = false,
22+
Properties = null,
23+
Type = "integer",
24+
Value = null
25+
},
26+
new Property() {
27+
Name = "statusDescription",
28+
Description = null,
29+
Format = null,
30+
Required = false,
31+
Properties = null,
32+
Type = "string",
33+
Value = null
34+
},
35+
new Property() {
36+
Name = "message",
37+
Description = null,
38+
Format = null,
39+
Required = false,
40+
Properties = null,
41+
Type = "string",
42+
Value = null
43+
},
44+
new Property() {
45+
Name = "errorCode",
46+
Description = null,
47+
Format = "int32",
48+
Required = false,
49+
Properties = null,
50+
Type = "integer",
51+
Value = null
52+
}
53+
}
54+
};
55+
}
56+
}
57+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using QAToolKit.Core.Models;
2+
using QAToolKit.Source.Swagger.Test.Fixtures.BicycleApi.Get.Helpers;
3+
using QAToolKit.Source.Swagger.Test.Fixtures.PetApi.Get.Helpers;
4+
using System.Collections.Generic;
5+
6+
namespace QAToolKit.Source.Swagger.Test.Fixtures.BicycleApi.Get
7+
{
8+
public static class GetBicycleByIdResponse
9+
{
10+
public static List<Response> Get()
11+
{
12+
return new List<Response>()
13+
{
14+
BicyclesResponse200.Get(),
15+
BicycleResponse400.Get()
16+
};
17+
}
18+
}
19+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
using QAToolKit.Core.Models;
2+
using System.Collections.Generic;
3+
4+
namespace QAToolKit.Source.Swagger.Test.Fixtures.BicycleApi.Get.Helpers
5+
{
6+
public static class BicycleObjectWithoutExampleValues
7+
{
8+
public static List<Property> GetProperties()
9+
{
10+
return new List<Property>()
11+
{
12+
new Property(){
13+
Name = "id",
14+
Description = "Bike Id",
15+
Format = "int32",
16+
Required = false,
17+
Properties = null,
18+
Type = "integer",
19+
Value = "1"
20+
},
21+
new Property(){
22+
Name = "name",
23+
Description = "Bike name",
24+
Format = null,
25+
Required = false,
26+
Properties = null,
27+
Type = "string",
28+
Value = "Foil"
29+
},
30+
new Property(){
31+
Name = "brand",
32+
Description = "Bicycle brand",
33+
Format = null,
34+
Required = false,
35+
Properties = null,
36+
Type = "string",
37+
Value = "Cannondale"
38+
},
39+
new Property(){
40+
Name = "BicycleType",
41+
Description = null,
42+
Format = "int32",
43+
Required = false,
44+
Properties = new List<Property>(){
45+
new Property()
46+
{
47+
Name = null,
48+
Description = null,
49+
Format = null,
50+
Required = false,
51+
Properties = null,
52+
Type = "string",
53+
Value = "0"
54+
},
55+
new Property()
56+
{
57+
Name = null,
58+
Description = null,
59+
Format = null,
60+
Required = false,
61+
Properties = null,
62+
Type = "string",
63+
Value = "1"
64+
},
65+
new Property()
66+
{
67+
Name = null,
68+
Description = null,
69+
Format = null,
70+
Required = false,
71+
Properties = null,
72+
Type = "string",
73+
Value = "2"
74+
},
75+
new Property()
76+
{
77+
Name = null,
78+
Description = null,
79+
Format = null,
80+
Required = false,
81+
Properties = null,
82+
Type = "string",
83+
Value = "3"
84+
}
85+
},
86+
Type = "enum",
87+
Value = null
88+
}
89+
};
90+
}
91+
}
92+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using QAToolKit.Core.Models;
2+
using System.Collections.Generic;
3+
4+
namespace QAToolKit.Source.Swagger.Test.Fixtures.BicycleApi.Get.Helpers
5+
{
6+
public static class BicyclesParameters
7+
{
8+
public static List<Parameter> Get(bool exampleValues)
9+
{
10+
if (exampleValues)
11+
{
12+
return new List<Parameter>()
13+
{
14+
new Parameter() {
15+
Name = "bicycleType",
16+
Location = Location.Query,
17+
Nullable = false,
18+
Type = "integer",
19+
Required = false,
20+
Value = null
21+
},
22+
new Parameter() {
23+
Name = "api-version",
24+
Location = Location.Query,
25+
Nullable = false,
26+
Type = "string",
27+
Required = false,
28+
Value = "1"
29+
},
30+
new Parameter() {
31+
Name = "X-version",
32+
Location = Location.Header,
33+
Nullable = false,
34+
Type = "string",
35+
Required = false,
36+
Value = null
37+
}
38+
};
39+
}
40+
else
41+
{
42+
return new List<Parameter>()
43+
{
44+
new Parameter() {
45+
Name = "bicycleType",
46+
Location = Location.Query,
47+
Nullable = false,
48+
Type = "integer",
49+
Required = false,
50+
Value = null
51+
},
52+
new Parameter() {
53+
Name = "api-version",
54+
Location = Location.Query,
55+
Nullable = false,
56+
Type = "string",
57+
Required = false,
58+
Value = null
59+
},
60+
new Parameter() {
61+
Name = "X-version",
62+
Location = Location.Header,
63+
Nullable = false,
64+
Type = "string",
65+
Required = false,
66+
Value = null
67+
}
68+
};
69+
}
70+
}
71+
}
72+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using QAToolKit.Core.Models;
2+
using System.Net;
3+
4+
namespace QAToolKit.Source.Swagger.Test.Fixtures.BicycleApi.Get.Helpers
5+
{
6+
public static class BicyclesResponse200
7+
{
8+
public static Response Get()
9+
{
10+
return new Response()
11+
{
12+
StatusCode = HttpStatusCode.OK,
13+
Type = ResponseType.Objects,
14+
Properties = BicycleObjectWithoutExampleValues.GetProperties()
15+
};
16+
}
17+
}
18+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using ExpectedObjects;
2+
using Microsoft.Extensions.Logging;
3+
using Newtonsoft.Json;
4+
using QAToolKit.Core.Models;
5+
using QAToolKit.Source.Swagger.Test.Fixtures.BicycleApi.Get;
6+
using QAToolKit.Source.Swagger.Test.Fixtures.BicycleApi.Get.Helpers;
7+
using QAToolKit.Source.Swagger.Test.Fixtures.PetApi.Get;
8+
using QAToolKit.Source.Swagger.Test.Fixtures.PetApi.Post;
9+
using System;
10+
using System.Collections.Generic;
11+
using System.IO;
12+
using System.Linq;
13+
using System.Net.Http;
14+
using System.Threading.Tasks;
15+
using Xunit;
16+
using Xunit.Abstractions;
17+
18+
namespace QAToolKit.Source.Swagger.Test.SwaggerTests.BicycleApi.Get
19+
{
20+
public class SwaggerProcessorGetBicycleByIdTests
21+
{
22+
private readonly ILogger<SwaggerProcessorGetBicycleByIdTests> _logger;
23+
24+
public SwaggerProcessorGetBicycleByIdTests(ITestOutputHelper testOutputHelper)
25+
{
26+
var loggerFactory = new LoggerFactory();
27+
loggerFactory.AddProvider(new XunitLoggerProvider(testOutputHelper));
28+
_logger = loggerFactory.CreateLogger<SwaggerProcessorGetBicycleByIdTests>();
29+
}
30+
31+
[Fact]
32+
public async Task PetsSwaggerGetPetByIdWithExampleValuesTest_Successfull()
33+
{
34+
var urlSource = new SwaggerUrlSource(options =>
35+
{
36+
options.AddBaseUrl(new Uri("https://qatoolkitapi.azurewebsites.net/"));
37+
options.AddRequestFilters(new RequestFilter()
38+
{
39+
EndpointNameWhitelist = new string[] { "GetAllBikes" }
40+
});
41+
options.UseSwaggerExampleValues = true;
42+
});
43+
44+
var requests = await urlSource.Load(new Uri[] {
45+
new Uri("https://qatoolkitapi.azurewebsites.net/swagger/v1/swagger.json")
46+
});
47+
48+
_logger.LogInformation(JsonConvert.SerializeObject(requests, Formatting.Indented));
49+
50+
Assert.NotNull(requests);
51+
Assert.Equal(1, requests.Count);
52+
Assert.Empty(requests.FirstOrDefault().AuthenticationTypes);
53+
Assert.Equal("https://qatoolkitapi.azurewebsites.net/", requests.FirstOrDefault().BasePath);
54+
Assert.Equal("Get all bikes", requests.FirstOrDefault().Description);
55+
Assert.Equal(HttpMethod.Get, requests.FirstOrDefault().Method);
56+
Assert.Equal("GetAllBikes", requests.FirstOrDefault().OperationId);
57+
Assert.Equal(3, requests.FirstOrDefault().Parameters.Count);
58+
Assert.Equal("/api/bicycles", requests.FirstOrDefault().Path);
59+
Assert.Empty(requests.FirstOrDefault().RequestBodies);
60+
Assert.Equal(2, requests.FirstOrDefault().Responses.Count);
61+
62+
var getBikesParameters = BicyclesParameters.Get(true).ToExpectedObject();
63+
getBikesParameters.ShouldEqual(requests.FirstOrDefault().Parameters);
64+
65+
var expectedPetsResponse = GetBicycleByIdResponse.Get().ToExpectedObject();
66+
expectedPetsResponse.ShouldEqual(requests.FirstOrDefault().Responses);
67+
68+
Assert.Equal("Get all bikes by filter", requests.FirstOrDefault().Summary);
69+
Assert.Collection(requests.FirstOrDefault().Tags, item =>
70+
{
71+
item = "Public";
72+
});
73+
Assert.Empty(requests.FirstOrDefault().TestTypes);
74+
}
75+
}
76+
}

src/QAToolKit.Source.Swagger/QAToolKit.Source.Swagger.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<PackageReference Include="Microsoft.OpenApi" Version="1.2.3" />
3838
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.2.3" />
3939
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
40-
<PackageReference Include="QAToolKit.Core" Version="0.1.5" />
40+
<PackageReference Include="QAToolKit.Core" Version="0.1.6" />
4141
</ItemGroup>
4242

4343
</Project>

src/QAToolKit.Source.Swagger/SwaggerOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class SwaggerOptions
3737
/// <summary>
3838
/// Use Swagger example values that come with Swagger file
3939
/// </summary>
40-
internal bool UseSwaggerExampleValues { get; set; } = false;
40+
public bool UseSwaggerExampleValues { get; set; } = false;
4141

4242
/// <summary>
4343
/// Add basic authentication

0 commit comments

Comments
 (0)