Skip to content

Commit 29ff97e

Browse files
committed
Update ReflectionHelperTests.cs
1 parent 3b9f5fe commit 29ff97e

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed

tests/Tests.CodeOfChaos.Extensions/ReflectionHelperTests.cs

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ namespace Tests.CodeOfChaos.Extensions;
1212
public class ReflectionHelperTests {
1313
private class TestClass
1414
{
15+
public TestClass(string nonNullable, string? nullable, int valueType, int? nullableValueType) { }
16+
1517
// ReSharper disable UnusedParameter.Local
1618
public static void MethodWithNullability(
1719
string nonNullable,
@@ -135,5 +137,122 @@ public async Task IsNullableValueType_ShouldReturnFalse_ForNullableReferenceType
135137
// Assert
136138
await Assert.That(result).IsFalse().Because("Expected parameter 'nullable' to not be a nullable value type (it's a nullable reference type).");
137139
}
140+
141+
142+
// -----------------------------------------------------------------------------------------------------------------
143+
// Methods
144+
// -----------------------------------------------------------------------------------------------------------------
145+
[Test]
146+
public async Task IsNullableReferenceType_ShouldReturnTrue_ForNullableReferenceType_InConstructor()
147+
{
148+
// Arrange
149+
ConstructorInfo constructor = typeof(TestClass).GetConstructors().First();
150+
ParameterInfo nullableParameter = constructor.GetParameters().First(p => p.Name == "nullable");
151+
152+
// Act
153+
bool result = nullableParameter.IsNullableReferenceType();
154+
155+
// Assert
156+
await Assert.That(result).IsTrue().Because("Expected parameter 'nullable' to be recognized as a nullable reference type.");
157+
}
158+
159+
[Test]
160+
public async Task IsNullableReferenceType_ShouldReturnFalse_ForNonNullableReferenceType_InConstructor()
161+
{
162+
// Arrange
163+
ConstructorInfo constructor = typeof(TestClass).GetConstructors().First();
164+
ParameterInfo nonNullableParameter = constructor.GetParameters().First(p => p.Name == "nonNullable");
165+
166+
// Act
167+
bool result = nonNullableParameter.IsNullableReferenceType();
168+
169+
// Assert
170+
await Assert.That(result).IsFalse().Because("Expected parameter 'nonNullable' to be recognized as a non-nullable reference type.");
171+
}
172+
173+
[Test]
174+
public async Task IsNullableReferenceType_ShouldReturnFalse_ForValueType_InConstructor()
175+
{
176+
// Arrange
177+
ConstructorInfo constructor = typeof(TestClass).GetConstructors().First();
178+
ParameterInfo valueTypeParameter = constructor.GetParameters().First(p => p.Name == "valueType");
179+
180+
// Act
181+
bool result = valueTypeParameter.IsNullableReferenceType();
182+
183+
// Assert
184+
await Assert.That(result).IsFalse().Because("Expected parameter 'valueType' to be recognized as a non-nullable reference type.");
185+
}
186+
187+
[Test]
188+
public async Task IsNullableReferenceType_ShouldReturnFalse_ForNullableValueType_InConstructor()
189+
{
190+
// Arrange
191+
ConstructorInfo constructor = typeof(TestClass).GetConstructors().First();
192+
ParameterInfo nullableValueTypeParameter = constructor.GetParameters().First(p => p.Name == "nullableValueType");
193+
194+
// Act
195+
bool result = nullableValueTypeParameter.IsNullableReferenceType();
196+
197+
// Assert
198+
await Assert.That(result).IsFalse().Because("Expected parameter 'nullableValueType' to not be recognized as a nullable reference type (it's a nullable value type).");
199+
}
200+
201+
[Test]
202+
public async Task IsNullableValueType_ShouldReturnFalse_ForReferenceType_InConstructor()
203+
{
204+
// Arrange
205+
ConstructorInfo constructor = typeof(TestClass).GetConstructors().First();
206+
ParameterInfo referenceTypeParameter = constructor.GetParameters().First(p => p.Name == "nonNullable");
207+
208+
// Act
209+
bool result = referenceTypeParameter.IsNullableValueType();
210+
211+
// Assert
212+
await Assert.That(result).IsFalse().Because("Expected parameter 'nonNullable' to not be a nullable value type (it's a reference type).");
213+
}
214+
215+
[Test]
216+
public async Task IsNullableValueType_ShouldReturnFalse_ForNonNullableValueType_InConstructor()
217+
{
218+
// Arrange
219+
ConstructorInfo constructor = typeof(TestClass).GetConstructors().First();
220+
ParameterInfo valueTypeParameter = constructor.GetParameters().First(p => p.Name == "valueType");
221+
222+
// Act
223+
bool result = valueTypeParameter.IsNullableValueType();
224+
225+
// Assert
226+
await Assert.That(result).IsFalse().Because("Expected parameter 'valueType' to not be a nullable value type (it's a non-nullable value type).");
227+
}
228+
229+
[Test]
230+
public async Task IsNullableValueType_ShouldReturnTrue_ForNullableValueType_InConstructor()
231+
{
232+
// Arrange
233+
ConstructorInfo constructor = typeof(TestClass).GetConstructors().First();
234+
ParameterInfo nullableValueTypeParameter = constructor.GetParameters().First(p => p.Name == "nullableValueType");
235+
236+
// Act
237+
bool result = nullableValueTypeParameter.IsNullableValueType();
238+
239+
// Assert
240+
await Assert.That(result).IsTrue().Because("Expected parameter 'nullableValueType' to be recognized as a nullable value type.");
241+
}
242+
243+
[Test]
244+
public async Task IsNullableValueType_ShouldReturnFalse_ForNullableReferenceType_InConstructor()
245+
{
246+
// Arrange
247+
ConstructorInfo constructor = typeof(TestClass).GetConstructors().First();
248+
ParameterInfo nullableParameter = constructor.GetParameters().First(p => p.Name == "nullable");
249+
250+
// Act
251+
bool result = nullableParameter.IsNullableValueType();
252+
253+
// Assert
254+
await Assert.That(result).IsFalse().Because("Expected parameter 'nullable' to not be a nullable value type (it's a nullable reference type).");
255+
}
256+
138257

139258
}

0 commit comments

Comments
 (0)