chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
Hi everyone,
I'm trying to use Reflective Mocks to test some code.

public class Class1
{
private Thread _thread;
private int _value;

public int GetValue()
{
_thread.Join();

this.PerformComplexManipulationsOfValue(); // private method

return _value;
}
}

Where some other code spins up a thread to retrieve the Value and stick it in "_value". I tried setting up the mock like this:

MockObject class1Mock = MockManager.MockObject(typeof(Class1), Constructor.Mocked, new object[0]);

// This would ideally cause _thread.Join() to simply return
MockManager.MockAll(typeof(Thread), Constructor.Mocked);

// See if the value is what we think it is
((Class1)class1Mock.Object).GetValue();


We can't mock Thread because it's in mscorlib.dll. I'd rather not use ObjectState to read the "_value" field. I would like to call GetValue() to do the work. Any idea what I could be doing?

Thanks!
asked by BigNis (1.1k points)

3 Answers

0 votes
Hi
I'm not sure I understand what is the code you are testing.
Is it PerformComplexManipulationsOfValue?
Or the other thread?
Where some other code spins up a thread to retrieve the Value and stick it in "_value".

It is not clear to me what the 'other code' is doing. Does it call to GetValue()?
Does it gets and sets _value?
answered by ohad (35.4k points)
0 votes
Pardon my example code. What I really want to do is be able to test GetValue() and get around the Thread.Join() call.
answered by BigNis (1.1k points)
0 votes
Hi
ok now I understand! :shock:
Unfortunately I don't see a solution in this case. :cry:
The feature is still in the works and will be available in future release. Hopefully not far.
answered by ohad (35.4k points)
...