Skip to content

Commit d462a9d

Browse files
committed
Review feedback: NullabilityTests
1 parent 945a803 commit d462a9d

File tree

2 files changed

+24
-30
lines changed

2 files changed

+24
-30
lines changed

test/OpenApiClientTests/SchemaProperties/NullableReferenceTypesDisabled/NullabilityTests.cs

+11-15
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,17 @@ namespace OpenApiClientTests.SchemaProperties.NullableReferenceTypesDisabled;
77

88
public sealed class NullabilityTests
99
{
10-
[Fact]
11-
public void Nullability_of_generated_types_is_as_expected()
10+
[Theory]
11+
[InlineData(nameof(ChickenAttributesInResponse.Name), NullabilityState.Unknown)]
12+
[InlineData(nameof(ChickenAttributesInResponse.NameOfCurrentFarm), NullabilityState.Unknown)]
13+
[InlineData(nameof(ChickenAttributesInResponse.Age), NullabilityState.NotNull)]
14+
[InlineData(nameof(ChickenAttributesInResponse.Weight), NullabilityState.NotNull)]
15+
[InlineData(nameof(ChickenAttributesInResponse.TimeAtCurrentFarmInDays), NullabilityState.Nullable)]
16+
[InlineData(nameof(ChickenAttributesInResponse.HasProducedEggs), NullabilityState.NotNull)]
17+
public void Nullability_of_generated_property_is_as_expected(string propertyName, NullabilityState expectedState)
1218
{
13-
PropertyInfo[] propertyInfos = typeof(ChickenAttributesInResponse).GetProperties();
14-
15-
PropertyInfo? propertyInfo = propertyInfos.FirstOrDefault(property => property.Name == nameof(ChickenAttributesInResponse.Name));
16-
propertyInfo.Should().BeNullable();
17-
18-
propertyInfo = propertyInfos.FirstOrDefault(property => property.Name == nameof(ChickenAttributesInResponse.NameOfCurrentFarm));
19-
propertyInfo.Should().BeNullable();
20-
21-
propertyInfo = propertyInfos.FirstOrDefault(property => property.Name == nameof(ChickenAttributesInResponse.Age));
22-
propertyInfo.Should().BeNonNullable();
23-
24-
propertyInfo = propertyInfos.FirstOrDefault(property => property.Name == nameof(ChickenAttributesInResponse.TimeAtCurrentFarmInDays));
25-
propertyInfo.Should().BeNullable();
19+
PropertyInfo[] properties = typeof(ChickenAttributesInResponse).GetProperties();
20+
PropertyInfo property = properties.Single(property => property.Name == propertyName);
21+
property.Should().HaveNullabilityState(expectedState);
2622
}
2723
}

test/OpenApiClientTests/SchemaProperties/NullableReferenceTypesEnabled/NullabilityTests.cs

+13-15
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,19 @@ namespace OpenApiClientTests.SchemaProperties.NullableReferenceTypesEnabled;
77

88
public sealed class NullabilityTests
99
{
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)
1220
{
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);
2624
}
2725
}

0 commit comments

Comments
 (0)