I’m trying to find a way to fake the result of a method called from within another method.
I have a ‘LoadData’ method which calls a separate helper to get some data and then it will transform it (I’m interested in testing the transformed result).
So I have code like this:
public class MyClass(){ public void LoadData(){ SomeProperty = Helper.GetSomeData(); } public object SomeProperty {get;set;} }
I want to have a known result from the Helper.GetSomeData() method. Can I use a mocking framework (I’ve got fairly limited experience with Rhino Mocks but am open to anything) to force an expected result? If so, how?
*Edit – yeah as expected I couldn’t achieve the hack I wanted, I’ll have to work out a better way to set up the data.
As far as I know, you should create an interface or a base abstract class for the Helper object. With Rhino Mocks you can then return the value you want.
Alternatively, you can add an overload for LoadData that accepts as parameters the data that you normally retrieve from the Helper object. This might even be easier.