我正在尝试在类中模拟一个实例。这是类(简化):
public void CreatePhotos(string elementType)
{
var foo = new PicturesCreation();
//some code here...
if (elementType == "IO")
{
foo.CreateIcons(client, new PicturesOfFrogsCreation(), periodFrom, periodTo)
}
}
所以我试图模拟这个'new PicturesOfFrogsCreation()'进行单元测试,看看是否使用这个参数调用了CreateIcons。我试图在我的测试中使用 Rhino Mocks/AssertWasCalled 方法来实现这一点,但它看起来不起作用,因为我只知道如何模拟接口。你知道是否可以模拟这个吗?
更新: PicturesCreation 类的代码:
internal sealed class PicturesCreation
{
public void CreateIcons(IPictures foo, int periodFrom, int periodTo)
{
foo.CreateIcons(periodFrom, periodTo);
}
}
和 PicturesOfFrogsCreation 的代码:
internal sealed class PicturesOfFrogsCreation : IPictures
{
public void CreateIcons(int periodFrom, int periodTo)
{
//Code that implements the method
}
}
我写了这个测试,但我不确定它是否写得好:
public void Create_commitment_transaction_should_be_called_for_internal_order()
{
IPicture fooStub = RhinoStubWrapper<IPicture>.CreateStubObject();
rebuildCommitmentsStub.StubMethod(x => x.CreateIcons(Arg<int>.Is.Anything, Arg<int>.Is.Anything));
PicturesProcess.CreatePhotos("IO");
rebuildCommitmentsStub.AssertWasCalled(x => x.CreateIcons(Arg<int>.Is.Anything,Arg<int>.Is.Anything));
}
提前致谢!
一种。