I tried to mix reflective and natural mocks and run into this situation.
Tested class:
public class MethodContainer
{
public static NameValueCollection CalledMethod(IDictionary<string, string> stuff)
{
return null;
}
public void CallingMethod()
{
Dictionary<string, string> stuff = new Dictionary<string, string>();
CalledMethod(stuff);
if (stuff.Count <= 0)
{
throw new InvalidOperationException();
}
}
}
Test:
[TestClass]
[ClearMocks]
public class UnitTest2
{
[TestMethod]
[VerifyMocks]
public void TestMethod2()
{
MockObject<MethodContainer> containerMockObject = MockManager.MockObject<MethodContainer>();
containerMockObject.Strict = true;
containerMockObject.StrictStatic = true;
containerMockObject.CallStatic.MethodSettings("CalledMethod").MockMethodCalled += delegate(object sender, MockMethodCallEventArgs e)
{
IDictionary<string, string> stuff = e.SentArguments[0] as IDictionary<string, string>;
stuff.Add("key1", "value1");
};
NameValueCollection output = new NameValueCollection();
MethodContainer container = containerMockObject.Object;
using (RecordExpectations recorder = RecorderManager.StartRecording())
{
container.CallingMethod();
recorder.CallOriginal();
recorder.ExpectAndReturn(MethodContainer.CalledMethod(null), output).IgnoreArguments();
}
container.CallingMethod();
}
}