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 there,

Question, I've written a topic on Isolator because I was so glad it provided me with some options I needed! :) But it still left me with a question.

You can find the item here.

In the 4th code block I used the following line in the recorder. How would I do this using reflective mocking?
someArray.SkipWhile(i => i < 2).First();


In the same code block, I also used the following line to get the mocked instance. How would I get such a mocked instance when I created it within the recorder?
Customer c = mockedCustomer.MockedInstance as Customer;


Thanks in advance,
Dennis
asked by dvdstelt (5.3k points)

2 Answers

0 votes
Anyone?
answered by dvdstelt (5.3k points)
0 votes
Hi Dennis,

Sorry for the not answering sooner.

The reflective part I'll need to check - Reflective does not lend it self too much towards lambda expressions. So I'll get back to you about this one.

For the second part, if you created the object inside the recorder block using new), you've actually created expectations on a future instance, so you don't have access to that instance.

If you want to use the instance outside the recording block, use RecorderManager.CreateMockedObject. It's not a future instance, but a current one, but from what I see that's what you need.

But, if I were you, I'd go with the new API. You'll get an instance you can set behavior on and verify expectations on with more clear and readable tests.

if you'd like we can go over this offline, and for example, rewrite your tests in the new API, as they appear in your post.

Thanks,
answered by gilz (14.5k points)
...