Unfortunately, you can't mock statics with RM. Instead, you need to either make it an instance object (if you own the code in question) or wrap the static call in your own wrapper class (thats non-static) and inject that dependency into the class with the DoWork() method (if you don't own the Utility class code).
This is (one of) the reason(s) to generally avoid statics where possible IMO. -Steve B. On Dec 2, 2011 4:47 PM, "Laksh" <[email protected]> wrote: > I have a " Worker" class which has a method "DoWork()". DoWork method > has several step to do work. it also make a call to static method of > Utility class. How do i mock this static utility? > > public interface IWorker > { > public void DoWork(IContext context); > } > > public class Worker:IWorker > { > public void DoWork(IContext context) > { > // Do something here > > Utility.Calculate(context.Info); > } > } > > -- > You received this message because you are subscribed to the Google Groups > "Rhino.Mocks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/rhinomocks?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rhinomocks?hl=en.
