Hello,
I whould like to know what I do wrong. Fire events inside DoInstead block won't work for me. I reproduce this issue in simple scenario:
public class FooClass
{
public event EventHandler<EventArgs> FooEvent;
public void Foo()
{
if (FooEvent != null)
{
FooEvent(this, EventArgs.Empty);
}
}
}
//this test works just fine
[TestMethod]
[Isolated]
public void TestMockes()
{
bool invoked = false;
FooClass obj = new FooClass();
obj.FooEvent += (s, a) => invoked = true;
Isolate.Invoke.Event(() => obj.FooEvent += null, this, EventArgs.Empty);
Assert.IsTrue(invoked);
}
//This test is the same as the previous one. I just changed event raising mechanism
[TestMethod]
[Isolated]
public void TestMockesFailure()
{
bool invoked = false;
FooClass obj = new FooClass();
obj.FooEvent += (s, a) => invoked = true;
Isolate.WhenCalled(() => obj.Foo()).DoInstead((c) =>
{
Isolate.Invoke.Event(() => { obj.FooEvent += null; }, this, EventArgs.Empty); //here I have got in runtime the exception below
});
obj.Foo();
Assert.IsTrue(invoked);
}
Exception details:
*** No method calls found in recording block. Please check:
* Are you trying to fake a field instead of a property?
* Are you are trying to fake mscorlib type?
TypeMock.TypeMockException occurred
Message="
*** No method calls found in recording block. Please check:
* Are you trying to fake a field instead of a property?
* Are you are trying to fake mscorlib type?"
Source="Typemock.ArrangeActAssert"
StackTrace:
at hc.a(Boolean A_0)
at h.a(Action A_0, b6 A_1)
at h.a(Action A_0, Object[] A_1)
at Test.cs:line 115
InnerException:
Can anyone say what can be wrong.
TIA,
Grammer