Hello,
we have a weired problem when using Rhino Mocks and Threads. I've tried to isolate the problem, but now I'm stuck to this:
[TestClass]
public class FoolTests
{
[TestMethod]
public void TestMethod_Scenario_Result()
{
for (int i = 0; i < 5; i++)
{
var fool = MockRepository.GenerateStub<IFool>();
fool.Stub(x => x.AmIFool).Return(false);
new Fool(fool);
}
}
}
public class Fool
{
private readonly IFool _fool;
private readonly Thread _thread;
public Fool(IFool fool)
{
_fool = fool;
_thread = new Thread(Foolish);
_thread.Start();
}
private void Foolish()
{
while (true)
{
var foo = _fool.Foolness;
}
}
}
public interface IFool
{
bool AmIFool { get; }
bool Foolness { get; set; }
}
Nearly all the time when running this test, I get "Test method FoolTests.TestMethod_Scenario_Result threw exception: System.InvalidOperationException: This action is invalid when the mock object is in replay state." on line "fool.Stub(x => x.AmIFool).Return(false);".
I have no idea what should be wrong here. Has anyone an idea or do I have to dig into the Rhino Mocks-code?