Hi Michael,
I have tried this scenario and it works for me, there must be some other issue here. (Perhaps in the Trace Listener, you could try doing a Console.WriteLine)
Here is the code that I tried
[Test]
public void TestEvents()
{
// Set trace output
Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
// Make 3 IList Mocks and call Count twice for each
MockObject mock1 = MockInterface(typeof(IList));
mock1.ExpectGetAlways("Count",1);
MockObject mock2 = MockInterface(typeof(IList));
mock2.ExpectGetAlways("Count",1);
MockObject mock3 = MockInterface(typeof(IList));
mock3.ExpectGetAlways("Count",1);
IList list1 = (IList)mock1.Object;
IList list2 = (IList)mock2.Object;
IList list3 = (IList)mock3.Object;
int a = list1.Count;
a=list1.Count;
a=list2.Count;
a=list2.Count;
a=list3.Count;
a=list3.Count;
}
private MockObject MockInterface(Type type)
{
mock= MockManager.MockObject(type);
// No need to make strict MockObjects are strict by default
//mock.Strict = true;
mock.MockMethodCalled += new MockMethodCalledEventHandler(LogMockMethodCalled);
}
private void LogMockMethodCalled(object sender, MockMethodCallEventArgs e)
{
string Message = string.Format("Method {0} mocked. Called from type {1}.",
e.CalledMethodName,
e.CalledType.FullName);
Trace.WriteLine(Message);
}
It prints:
Method get_Count mocked. Called from type MockIList.
Method get_Count mocked. Called from type MockIList.
Method get_Count mocked. Called from type MockIList.
Method get_Count mocked. Called from type MockIList.
Method get_Count mocked. Called from type MockIList.
Method get_Count mocked. Called from type MockIList.
Please tell me if the above code works for you