对于一个项目,我使用 MEF 框架的 CompositeContainer 类。现在我想做一个单元测试(使用起订量)来验证是否调用了 ComposeParts(这是 AttributedModelServices 中的扩展方法)方法。
仅仅用 moq 模拟它是行不通的,因为该方法不是虚拟的。我找到了一些方法来做到这一点,但所有这些都让我改变了 CompositeContainer 类,这是我做不到的。
起订量中有没有办法测试是否调用了外部 3rd 方库的非虚拟方法?
提前感谢您的回复。
示例代码:
public void Load(string path, CompositionContainer container)
{
container.ComposeParts(this);
}
这里的容器来自 MEF 库, ComposeParts 是 System.ComponentModel.Composition 命名空间中的扩展方法:
//
// Summary:
// Creates composable parts from an array of attributed objects and composes
// them in the specified composition container.
//
// Parameters:
// container:
// The composition container to perform composition in.
//
// attributedParts:
// An array of attributed objects to compose.
public static void ComposeParts(this CompositionContainer container, params object[] attributedParts);