This is a migrated thread and some comments may be shown as answers.

Migrating from MS Moles

1 Answer 18 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Phil
Top achievements
Rank 1
Phil asked on 14 Mar 2013, 04:53 PM
We have many test projects that use Microsoft Moles extensively to detour/intercept calls to dependencies. Can JustMock perform detours in the same way Moles does, or does it require target classes to support some kind of dependency injection as I have seen in the examples so far? (I haven't studied JustMock extensively yet, just saw a few examples.) To be clear, for the time being, unfortunately, we need to test classes that do not support any sort of dependency injection (i.e., we can't modify the dependent classes yet), so we're not talking about just creating mocks here. Here's an example. It intercepts all calls to the GetError method on any instance of the SomeClass class. Can JustMock do stuff like this?
MSomeClass.AllInstances.GetError = (instance) =>
    {
        return string.Empty;
    };

1 Answer, 1 is accepted

Sort by
0
Kaloyan
Telerik team
answered on 18 Mar 2013, 01:35 PM
Hello Phil,

Thank you for contacting Telerik support.

To help you further, I would suggest you to check this article about Future Mocking with JustMock.

Having the above, I would use JustMock to write your arrange the following way:
var mSomeClassMock = Mock.Create<MSomeClass>();
 
var expected = string.Empty;
 
Mock.Arrange(() => mSomeClassMock.GetError()).IgnoreInstance().Return(expected);

This will intercept all "MSomeClass" instances and will arrange the "GetError()" method to return an empty string when called.

I hope this helps. Please contact us further if you have more questions.

Kind regards,
Kaloyan
the Telerik team
Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our forums, or our JustTrace or JustMock portals.
Tags
General Discussions
Asked by
Phil
Top achievements
Rank 1
Answers by
Kaloyan
Telerik team
Share this question
or