我需要一些如何对这种方法进行单元测试。问题是 FsFileGroupFile 不容易模拟,它具有复杂的构造函数要求并且不直接使用接口。_blockReaderFactory
另一方面是一个接口,因此很容易模拟。我怎么能模拟这么复杂的对象。我正在使用 Rhino Mocks 和 Microsoft 单元测试框架。有人有想法么?
public void ReadGeneral(FsFileGroupFile a_file, FileItemData a_fileItemData)
{
try
{
var blockReader = _blockReaderFactory.Create(a_file.File.FullName, "CabinetData/StartData");
var version = blockReader.ReadVersion();
var name = blockReader.ReadString();
var type = blockReader.ReadString();
var defaultHeight = blockReader.ReadDouble();
var defaultWidth = blockReader.ReadDouble();
var defaultDepth = blockReader.ReadDouble();
a_fileItemData.Name = name;
a_fileItemData.DefaultWidth = defaultWidth * 100.0;
a_fileItemData.DefaultHeight = defaultHeight * 100.0;
a_fileItemData.DefaultDepth = defaultDepth * 100.0;
}
catch (Exception ex)
{
throw new IOException("General data could not be read from block data.", ex);
}
}