@@ -7,21 +7,19 @@ namespace OpenApiClientTests.SchemaProperties.NullableReferenceTypesEnabled;
7
7
8
8
public sealed class NullabilityTests
9
9
{
10
- [ Fact ]
11
- public void Nullability_of_generated_types_is_as_expected ( )
10
+ [ Theory ]
11
+ [ InlineData ( nameof ( CowAttributesInResponse . Name ) , NullabilityState . NotNull ) ]
12
+ [ InlineData ( nameof ( CowAttributesInResponse . NameOfCurrentFarm ) , NullabilityState . NotNull ) ]
13
+ [ InlineData ( nameof ( CowAttributesInResponse . NameOfPreviousFarm ) , NullabilityState . Nullable ) ]
14
+ [ InlineData ( nameof ( CowAttributesInResponse . Nickname ) , NullabilityState . NotNull ) ]
15
+ [ InlineData ( nameof ( CowAttributesInResponse . Age ) , NullabilityState . NotNull ) ]
16
+ [ InlineData ( nameof ( CowAttributesInResponse . Weight ) , NullabilityState . NotNull ) ]
17
+ [ InlineData ( nameof ( CowAttributesInResponse . TimeAtCurrentFarmInDays ) , NullabilityState . Nullable ) ]
18
+ [ InlineData ( nameof ( CowAttributesInResponse . HasProducedMilk ) , NullabilityState . NotNull ) ]
19
+ public void Nullability_of_generated_property_is_as_expected ( string propertyName , NullabilityState expectedState )
12
20
{
13
- PropertyInfo [ ] propertyInfos = typeof ( CowAttributesInResponse ) . GetProperties ( ) ;
14
-
15
- PropertyInfo ? propertyInfo = propertyInfos . FirstOrDefault ( property => property . Name == nameof ( CowAttributesInResponse . Name ) ) ;
16
- propertyInfo . Should ( ) . BeNonNullable ( ) ;
17
-
18
- propertyInfo = propertyInfos . FirstOrDefault ( property => property . Name == nameof ( CowAttributesInResponse . NameOfPreviousFarm ) ) ;
19
- propertyInfo . Should ( ) . BeNullable ( ) ;
20
-
21
- propertyInfo = propertyInfos . FirstOrDefault ( property => property . Name == nameof ( CowAttributesInResponse . Age ) ) ;
22
- propertyInfo . Should ( ) . BeNonNullable ( ) ;
23
-
24
- propertyInfo = propertyInfos . FirstOrDefault ( property => property . Name == nameof ( CowAttributesInResponse . TimeAtCurrentFarmInDays ) ) ;
25
- propertyInfo . Should ( ) . BeNullable ( ) ;
21
+ PropertyInfo [ ] properties = typeof ( CowAttributesInResponse ) . GetProperties ( ) ;
22
+ PropertyInfo property = properties . Single ( property => property . Name == propertyName ) ;
23
+ property . Should ( ) . HaveNullabilityState ( expectedState ) ;
26
24
}
27
25
}
0 commit comments