Natural Mocks becoming more intelligent
Natural Mocks automatically mocks everything. This includes return values. So the following code:
using (RecordedExpecations recorder = RecorderManager.StartRecording()) { DummyClass.DoWork(); recorder.Return(new SqlInt32(1)); }
Won’t work as expected because SqlInt32 is being mocked.
This has bugged me a few times and I simply created the return value outside the recorder.
SqlInt32 mockValue = new SqlInt32(1)); using (RecordedExpecations recorder = RecorderManager.StartRecording()) { DummyClass.DoWork(); recorder.Return(mockValue); }
But this is not really nice, and a few customers have pointed out that this could be annoying!
So we are going to implement a feature that will know that you are creating a return value and will not mock it!
This way the first code will work as expected. Of course if you want to return a mocked value you will have to create the mock before, this might lead to non backward compatibility.
To those who want the first code to work as before (although I don’t think that anyone would), mock the return value before calling the recorded statements, and change the above code to:
using (RecordedExpecations recorder = RecorderManager.StartRecording()) { SqlInt32 mock = new SqlInt32(1); DummyClass.DoWork(); recorder.Return(mock); }
Of course if you are going to do that, you will have to define the behavior of the SqlInt32 and you might as well use ChainedMocks
using (RecordedExpecations recorder = RecorderManager.StartRecording()) { DummyClass.DoWork().Value; recorder.Return(1); }
What do you think about this feature?
One Response to “Natural Mocks becoming more intelligent”
1 Eli Lopian’s Blog (TypeMock) » Blog Archive » Innovation in Practice? 29 March 2007 @ 2:42 pm
[…] Deep - Perhaps supporting Multi-Threads could be called deep.Intelligent - Well we just got more intelligent (Perhaps one day TypeMock will write the mocks itself)Complete - We are trying to give a complete solution. We have a Pre-Sales and Support Group although I know that we need more examples and training materialsElegant - I think that NaturalMocks is.Emotize - Hmm? Do you feel passionate about TypeMock? […]
Leave a Reply