@@ -20,160 +20,74 @@ public NullabilityTests(
20
20
testContext . SwaggerDocumentOutputPath = "test/OpenApiClientTests/ResourceFieldValidation/NullableReferenceTypesDisabled/ModelStateValidationDisabled" ;
21
21
}
22
22
23
- [ Fact ]
24
- public async Task Schema_property_for_reference_type_attribute_is_nullable ( )
23
+ [ Theory ]
24
+ [ InlineData ( "referenceType" ) ]
25
+ [ InlineData ( "requiredReferenceType" ) ]
26
+ [ InlineData ( "nullableValueType" ) ]
27
+ [ InlineData ( "requiredNullableValueType" ) ]
28
+ public async Task Schema_property_for_attribute_is_nullable ( string jsonPropertyName )
25
29
{
26
30
// Act
27
31
JsonElement document = await _testContext . GetSwaggerDocumentAsync ( ) ;
28
32
29
33
// Assert
30
34
document . ShouldContainPath ( "components.schemas.resourceAttributesInResponse.properties" ) . With ( schemaProperties =>
31
35
{
32
- schemaProperties . ShouldContainPath ( "referenceType" ) . With ( schemaProperty =>
36
+ schemaProperties . ShouldContainPath ( jsonPropertyName ) . With ( schemaProperty =>
33
37
{
34
38
schemaProperty . ShouldContainPath ( "nullable" ) . With ( nullableProperty => nullableProperty . ValueKind . Should ( ) . Be ( JsonValueKind . True ) ) ;
35
39
} ) ;
36
40
} ) ;
37
41
}
38
42
39
- [ Fact ]
40
- public async Task Schema_property_for_required_reference_type_attribute_is_nullable ( )
43
+ [ Theory ]
44
+ [ InlineData ( "valueType" ) ]
45
+ [ InlineData ( "requiredValueType" ) ]
46
+ public async Task Schema_property_for_attribute_is_not_nullable ( string jsonPropertyName )
41
47
{
42
48
// Act
43
49
JsonElement document = await _testContext . GetSwaggerDocumentAsync ( ) ;
44
50
45
51
// Assert
46
52
document . ShouldContainPath ( "components.schemas.resourceAttributesInResponse.properties" ) . With ( schemaProperties =>
47
53
{
48
- schemaProperties . ShouldContainPath ( "requiredReferenceType" ) . With ( schemaProperty =>
49
- {
50
- schemaProperty . ShouldContainPath ( "nullable" ) . With ( nullableProperty => nullableProperty . ValueKind . Should ( ) . Be ( JsonValueKind . True ) ) ;
51
- } ) ;
52
- } ) ;
53
- }
54
-
55
- [ Fact ]
56
- public async Task Schema_property_for_value_type_attribute_is_not_nullable ( )
57
- {
58
- // Act
59
- JsonElement document = await _testContext . GetSwaggerDocumentAsync ( ) ;
60
-
61
- // Assert
62
- document . ShouldContainPath ( "components.schemas.resourceAttributesInResponse.properties" ) . With ( schemaProperties =>
63
- {
64
- schemaProperties . ShouldContainPath ( "valueType" ) . With ( schemaProperty =>
54
+ schemaProperties . ShouldContainPath ( jsonPropertyName ) . With ( schemaProperty =>
65
55
{
66
56
schemaProperty . ShouldNotContainPath ( "nullable" ) ;
67
57
} ) ;
68
58
} ) ;
69
59
}
70
60
71
- [ Fact ]
72
- public async Task Schema_property_for_required_value_type_attribute_is_not_nullable ( )
73
- {
74
- // Act
75
- JsonElement document = await _testContext . GetSwaggerDocumentAsync ( ) ;
76
-
77
- // Assert
78
- document . ShouldContainPath ( "components.schemas.resourceAttributesInResponse.properties" ) . With ( schemaProperties =>
79
- {
80
- schemaProperties . ShouldContainPath ( "requiredValueType" ) . With ( schemaProperty =>
81
- {
82
- schemaProperty . ShouldNotContainPath ( "nullable" ) ;
83
- } ) ;
84
- } ) ;
85
- }
86
-
87
- [ Fact ]
88
- public async Task Schema_property_for_nullable_value_type_attribute_is_nullable ( )
89
- {
90
- // Act
91
- JsonElement document = await _testContext . GetSwaggerDocumentAsync ( ) ;
92
-
93
- // Assert
94
- document . ShouldContainPath ( "components.schemas.resourceAttributesInResponse.properties" ) . With ( schemaProperties =>
95
- {
96
- schemaProperties . ShouldContainPath ( "nullableValueType" ) . With ( schemaProperty =>
97
- {
98
- schemaProperty . ShouldContainPath ( "nullable" ) . With ( nullableProperty => nullableProperty . ValueKind . Should ( ) . Be ( JsonValueKind . True ) ) ;
99
- } ) ;
100
- } ) ;
101
- }
102
-
103
- [ Fact ]
104
- public async Task Schema_property_for_required_nullable_value_type_attribute_is_nullable ( )
105
- {
106
- // Act
107
- JsonElement document = await _testContext . GetSwaggerDocumentAsync ( ) ;
108
-
109
- // Assert
110
- document . ShouldContainPath ( "components.schemas.resourceAttributesInResponse.properties" ) . With ( schemaProperties =>
111
- {
112
- schemaProperties . ShouldContainPath ( "requiredNullableValueType" ) . With ( schemaProperty =>
113
- {
114
- schemaProperty . ShouldContainPath ( "nullable" ) . With ( nullableProperty => nullableProperty . ValueKind . Should ( ) . Be ( JsonValueKind . True ) ) ;
115
- } ) ;
116
- } ) ;
117
- }
118
-
119
- [ Fact ]
120
- public async Task Schema_property_for_to_one_relationship_is_nullable ( )
61
+ [ Theory ]
62
+ [ InlineData ( "toOne" ) ]
63
+ [ InlineData ( "requiredToOne" ) ]
64
+ public async Task Schema_property_for_relationship_is_nullable ( string jsonPropertyName )
121
65
{
122
66
// Act
123
67
JsonElement document = await _testContext . GetSwaggerDocumentAsync ( ) ;
124
68
125
69
// Assert
126
70
document . ShouldContainPath ( "components.schemas.resourceRelationshipsInPostRequest.properties" ) . With ( schemaProperties =>
127
71
{
128
- schemaProperties . ShouldContainPath ( "toOne .$ref") . WithSchemaReferenceId ( schemaReferenceId =>
72
+ schemaProperties . ShouldContainPath ( $ " { jsonPropertyName } .$ref") . WithSchemaReferenceId ( schemaReferenceId =>
129
73
{
130
74
document . ShouldContainPath ( $ "components.schemas.{ schemaReferenceId } .properties.data.oneOf[1].$ref") . ShouldBeSchemaReferenceId ( "nullValue" ) ;
131
75
} ) ;
132
76
} ) ;
133
77
}
134
78
135
- [ Fact ]
136
- public async Task Schema_property_for_required_to_one_relationship_is_nullable ( )
137
- {
138
- // Act
139
- JsonElement document = await _testContext . GetSwaggerDocumentAsync ( ) ;
140
-
141
- // Assert
142
- document . ShouldContainPath ( "components.schemas.resourceRelationshipsInPostRequest.properties" ) . With ( schemaProperties =>
143
- {
144
- schemaProperties . ShouldContainPath ( "requiredToOne.$ref" ) . WithSchemaReferenceId ( schemaReferenceId =>
145
- {
146
- document . ShouldContainPath ( $ "components.schemas.{ schemaReferenceId } .properties.data.oneOf[1].$ref") . ShouldBeSchemaReferenceId ( "nullValue" ) ;
147
- } ) ;
148
- } ) ;
149
- }
150
-
151
- [ Fact ]
152
- public async Task Schema_property_for_to_many_relationship_is_not_nullable ( )
153
- {
154
- // Act
155
- JsonElement document = await _testContext . GetSwaggerDocumentAsync ( ) ;
156
-
157
- // Assert
158
- document . ShouldContainPath ( "components.schemas.resourceRelationshipsInPostRequest.properties" ) . With ( schemaProperties =>
159
- {
160
- schemaProperties . ShouldContainPath ( "toMany.$ref" ) . WithSchemaReferenceId ( schemaReferenceId =>
161
- {
162
- document . ShouldContainPath ( $ "components.schemas.{ schemaReferenceId } .properties.data") . ShouldNotContainPath ( "oneOf[1].$ref" ) ;
163
- } ) ;
164
- } ) ;
165
- }
166
-
167
- [ Fact ]
168
- public async Task Schema_property_for_required_to_many_relationship_is_not_nullable ( )
79
+ [ Theory ]
80
+ [ InlineData ( "toMany" ) ]
81
+ [ InlineData ( "requiredToMany" ) ]
82
+ public async Task Schema_property_for_relationship_is_not_nullable ( string jsonPropertyName )
169
83
{
170
84
// Act
171
85
JsonElement document = await _testContext . GetSwaggerDocumentAsync ( ) ;
172
86
173
87
// Assert
174
88
document . ShouldContainPath ( "components.schemas.resourceRelationshipsInPostRequest.properties" ) . With ( schemaProperties =>
175
89
{
176
- schemaProperties . ShouldContainPath ( "requiredToMany .$ref") . WithSchemaReferenceId ( schemaReferenceId =>
90
+ schemaProperties . ShouldContainPath ( $ " { jsonPropertyName } .$ref") . WithSchemaReferenceId ( schemaReferenceId =>
177
91
{
178
92
document . ShouldContainPath ( $ "components.schemas.{ schemaReferenceId } .properties.data") . ShouldNotContainPath ( "oneOf[1].$ref" ) ;
179
93
} ) ;
0 commit comments