Migrating from MS Moles

2 posts, 0 answers
  1. Phil
    Phil avatar
    7 posts
    Member since:
    Sep 2010

    Posted 14 Mar 2013 Link to this post

    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;
  2. Kaloyan
    Kaloyan avatar
    880 posts

    Posted 18 Mar 2013 Link to this post

    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,
    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.
Back to Top