1
+ using System . Net . Http ;
2
+ using System . Threading . Tasks ;
3
+
4
+ using FluentAssertions ;
5
+
6
+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
7
+
8
+ using Newtonsoft . Json ;
9
+ using Newtonsoft . Json . Linq ;
10
+
11
+ namespace Microsoft . Azure . WebJobs . Extensions . OpenApi . Document . Tests
12
+ {
13
+ [ TestClass ]
14
+ [ TestCategory ( Constants . TestCategory ) ]
15
+ public class Post_ApplicationJson_Double_Tests
16
+ {
17
+ private static HttpClient http = new HttpClient ( ) ;
18
+
19
+ private JObject _doc ;
20
+
21
+ [ TestInitialize ]
22
+ public async Task Init ( )
23
+ {
24
+ var json = await http . GetStringAsync ( Constants . OpenApiDocEndpoint ) . ConfigureAwait ( false ) ;
25
+ this . _doc = JsonConvert . DeserializeObject < JObject > ( json ) ;
26
+ }
27
+
28
+ [ DataTestMethod ]
29
+ [ DataRow ( "/post-applicationjson-double" , "post" ) ]
30
+ public void Given_OpenApiDocument_Then_It_Should_Return_OperationRequestBody ( string path , string operationType )
31
+ {
32
+ var requestBody = this . _doc [ "paths" ] [ path ] [ operationType ] [ "requestBody" ] ;
33
+
34
+ requestBody . Should ( ) . NotBeNull ( ) ;
35
+ }
36
+
37
+ [ DataTestMethod ]
38
+ [ DataRow ( "/post-applicationjson-double" , "post" , "text/plain" ) ]
39
+ public void Given_OpenApiDocument_Then_It_Should_Return_OperationRequestBodyContentType ( string path , string operationType , string contentType )
40
+ {
41
+ var content = this . _doc [ "paths" ] [ path ] [ operationType ] [ "requestBody" ] [ "content" ] ;
42
+
43
+ content [ contentType ] . Should ( ) . NotBeNull ( ) ;
44
+ }
45
+
46
+ [ DataTestMethod ]
47
+ [ DataRow ( "/post-applicationjson-double" , "post" , "text/plain" , "number" , "double" ) ]
48
+ public void Given_OpenApiDocument_Then_It_Should_Return_OperationRequestBodyContentTypeSchema ( string path , string operationType , string contentType , string propertyType , string propertyFormat )
49
+ {
50
+ var content = this . _doc [ "paths" ] [ path ] [ operationType ] [ "requestBody" ] [ "content" ] ;
51
+
52
+ var value = content [ contentType ] [ "schema" ] ;
53
+
54
+ value . Should ( ) . NotBeNull ( ) ;
55
+ value . Value < string > ( "type" ) . Should ( ) . Be ( propertyType ) ;
56
+ value . Value < string > ( "format" ) . Should ( ) . Be ( propertyFormat ) ;
57
+ }
58
+
59
+ [ DataTestMethod ]
60
+ [ DataRow ( "/post-applicationjson-double" , "post" , "200" ) ]
61
+ public void Given_OpenApiDocument_Then_It_Should_Return_OperationResponse ( string path , string operationType , string responseCode )
62
+ {
63
+ var responses = this . _doc [ "paths" ] [ path ] [ operationType ] [ "responses" ] ;
64
+
65
+ responses [ responseCode ] . Should ( ) . NotBeNull ( ) ;
66
+ }
67
+
68
+ [ DataTestMethod ]
69
+ [ DataRow ( "/post-applicationjson-double" , "post" , "200" , "application/json" ) ]
70
+ public void Given_OpenApiDocument_Then_It_Should_Return_OperationResponseContentType ( string path , string operationType , string responseCode , string contentType )
71
+ {
72
+ var content = this . _doc [ "paths" ] [ path ] [ operationType ] [ "responses" ] [ responseCode ] [ "content" ] ;
73
+
74
+ content [ contentType ] . Should ( ) . NotBeNull ( ) ;
75
+ }
76
+
77
+ [ DataTestMethod ]
78
+ [ DataRow ( "/post-applicationjson-double" , "post" , "200" , "application/json" , "doubleObjectModel" ) ]
79
+ public void Given_OpenApiDocument_Then_It_Should_Return_OperationResponseContentTypeSchema ( string path , string operationType , string responseCode , string contentType , string reference )
80
+ {
81
+ var content = this . _doc [ "paths" ] [ path ] [ operationType ] [ "responses" ] [ responseCode ] [ "content" ] ;
82
+
83
+ var @ref = content [ contentType ] [ "schema" ] [ "$ref" ] ;
84
+
85
+ @ref . Value < string > ( ) . Should ( ) . Be ( $ "#/components/schemas/{ reference } ") ;
86
+ }
87
+
88
+ [ DataTestMethod ]
89
+ [ DataRow ( "doubleObjectModel" , "object" ) ]
90
+ public void Given_OpenApiDocument_Then_It_Should_Return_ComponentSchema ( string @ref , string refType )
91
+ {
92
+ var schemas = this . _doc [ "components" ] [ "schemas" ] ;
93
+
94
+ var schema = schemas [ @ref ] ;
95
+
96
+ schema . Should ( ) . NotBeNull ( ) ;
97
+ schema . Value < string > ( "type" ) . Should ( ) . Be ( refType ) ;
98
+ }
99
+
100
+ [ DataTestMethod ]
101
+ [ DataRow ( "doubleObjectModel" , "doubleValue" , "number" , "double" ) ]
102
+ public void Given_OpenApiDocument_Then_It_Should_Return_ComponentSchemaProperty ( string @ref , string propertyName , string propertyType , string propertyFormat )
103
+ {
104
+ var properties = this . _doc [ "components" ] [ "schemas" ] [ @ref ] [ "properties" ] ;
105
+
106
+ var value = properties [ propertyName ] ;
107
+
108
+ value . Should ( ) . NotBeNull ( ) ;
109
+ value . Value < string > ( "type" ) . Should ( ) . Be ( propertyType ) ;
110
+ value . Value < string > ( "format" ) . Should ( ) . Be ( propertyFormat ) ;
111
+ }
112
+ }
113
+ }
0 commit comments