Have you ever tried to do something akin to the following?
[Fact]
public void ConvertClassToSubClass_Converts()
{
// Arrange
var parentClass = new SimpleTestClass();
parentClass.Property1 = "test";
// Act
var childClass = parentClass as SimpleTestSubClass;
// Assert
Assert.Equal("test", childClass.Property1);
}
This is a simple Xunit (failing) test. The reason it fails is because you (or I) am trying to cast a general type to a specific, and C# is complaining that this may not be possible; consequently, you will get null (or for a hard cast, you’ll get an InvalidCastException).
Have you ever tried to do something akin to the following?
[Fact]
public void ConvertClassToSubClass_Converts()
{
// Arrange
var parentClass = new SimpleTestClass();
parentClass.Property1 = “test”;
// Act
var childClass = parentClass as SimpleTestSubClass;
// Assert
Assert.Equal(“test”, childClass.Property1);
}
This is a simple Xunit (failing) test. The reason it fails is because you (or I) am trying to cast a general type to a specific, and C# is complaining that this may not be possible; consequently, you will get null (or for a hard cast, you’ll get an InvalidCastException). […]