Hi,
You should use
MockAll or use
Mock 3 times (see examples below).
:idea: The reason for this is that:
each
Mock controls
ONE instance of the Type.
MockAll controls
ALL instances.
For more information see
Understanding Instance Mocking in the User Guide.
Here is the detailed test:
[Test]
public void Test()
{
int count = 3;
// mock ALL instances of Class1
Mock mock = MockManager.MockAll(typeof (Class1));
mock.ExpectCall("Init", count);
// could also use: mock.ExpectAlways("Init")
// if the number of times in not important
Class1 ins;
for (int i = 0; i < count; i++)
{
ins = Class1.Instance;
}
}
or you could use the following:
[Test]
public void Test()
{
int count = 3;
// mock 3 instances of Class1
for (int i = 0; i < count; i++)
{
Mock mock = MockManager.Mock(typeof (Class1));
mock.ExpectCall("Init");
}
Class1 ins;
for (int i = 0; i < count; i++)
{
ins = Class1.Instance;
}
}