【发布时间】:2015-04-14 10:29:28
【问题描述】:
我的 .cs 文件中有如下代码
public IfileGroup Placefile(int quantity, IFileGroup destfile, ILoc location)
{
fileGroup fg = null;
cg = this.TransferFile(quantity, destfile as FileGroup, location);
}
所以在我的测试文件中,我创建了这样的模拟对象
Mock< IFileGroup > frp = new Mock< IFileGroup >();
frp.Setup(x => x.FileInfo).Returns("FileAvailable");
Mock<ILoc> locationMock;
locationMock.Setup(x => x.FileLocationId).Returns("10");
并调用函数
FileGroup target = new FileGroup ();
var result = target.Placefile(4, frp.Object, locationMock.Object);
但在调试时,当控制转到函数 Placefile 时,它会将 destfile 作为 null 传递,有没有办法从模拟对象向下转换为原始 CLR 对象?
【问题讨论】:
标签: c# unit-testing casting moq