0

我下面有两节课。我在测试中使用 Rhino Mockshex为类对象创建了一个存根。Hexagon如果我运行测试,它会在存根上调用强制转换操作时引发异常。

如何设置hex存根的行为以允许对其执行强制转换?

public class Shape
{
    //some properties and methods here
    public void PrintProperties()
    {
    }
}

public class Hexagon : Shape
{
    // some properties and methods and override
}

public static void main (string[] args)
{
    Hexagon hex = new Hexagon()

    var parentShape = (Shape)hex; // this is the explicit cast

    parentShape.PrintProperties()
}

谢谢

4

0 回答 0