Doh!
I was about to post a ranting reply about how could adding a Thread.Sleep to the test fix this, and it took me a while to see that you have changed from
MockManager.VerifyWithTimeout
to
mockedDependant.VerifyWithTimeout
in fact, the Thread.Sleep is not necessary at all, as VerifyWithTimeout blocks for the timeout anyway.
What I am confused about now, is WHEN I should be doing this? The documentaiton says to use MockManager.VerifyWithTimeout?
If I change my code to NOT be a singleton, and just be a class instantiated by the worker thread, then MockManager.VerifyWithTimeout works as advertised (see below).
Perhaps the docs need to be updated?
Thank you for the help though!
Sincerely
Pete
public class AsyncTest {
[TestInitialize()]
public void MyTestInitialize()
{
MockManager.Init();
}
[TestMethod]
public void TestMethod1()
{
ClassUnderTest classUnderTest = new ClassUnderTest();
Mock mockedDependant = MockManager.Mock(typeof (DependantClass));
mockedDependant.Strict = true;
mockedDependant.ExpectAndReturn("DoSomething", "string from MOCKED DependantClass");
classUnderTest.MethodUnderTest();
MockManager.VerifyWithTimeout(5 * 1000);
Assert.AreSame("string from MOCKED DependantClass", classUnderTest.Message);
}
}
public class ClassUnderTest {
public string Message;
public void MethodUnderTest()
{
WaitCallback callback = new WaitCallback(Process);
ThreadPool.QueueUserWorkItem(callback);
}
public void Process(object state)
{
DependantClass dependantClass = new DependantClass();
Message = dependantClass.DoSomething();
}
}
public class DependantClass {
public string DoSomething()
{
return "String from REAL DependantClass";
}
}
________
BMW M2B15 HISTORY