It looks to me that you are using some kind of DI container, so is it
not possible for you to use constructor injection for your object, eg.

public class LoadHandler: ILoadHandler
{
  private ILoadController _loadController;

   public LoadHandler(ILoadController loadController)
   {
     _loadController = loadController;
   }
}

If you can do this, then you simply mock the ILoadController and pass
the mock in to your call to construct LoadHandler in the test ...

[Test]
SomeMeaningfulTestName()
{
    var controllerStub = MockRepository.GenerateStub<ILoadController>
();
    controllerStub.Stub(c=>c.GetLoads).Return(MyMockDataSet);
    var handler = new LoadHander(controllerStub);

    // ACTION


    // ASSERT
}

On Nov 11, 7:48 pm, joshlrogers <[email protected]> wrote:
> I am new to mocking frameworks, haven't ever used one.  With that said
> I have no idea if any mocking framework more or less Rhino mocks is
> capable of doing what I am needing.
>
> I have a handler class that does just that it handles all the actions
> and data flow for a particular module of my application.  I am writing
> unit tests against this handler class, and it is getting quite
> burdensome because this handler class makes reads and writes to the
> DB.  I want to mock the data access classes that the handler class
> uses and keep the logic of the handler class itself.  However, I am
> unable to see how to do this.
>
> I am able to mock the handler class, but because I intercept the calls
> to the methods and return just what I say it doesn't test the logic of
> the handler class itself.  This handler class has instantiations of
> the data access objects and those are what I am trying to mock.  For
> instance a contrived example would be:
>
> public class LoadHandler: ILoadHandler
> {
>
>   private ILoadController _LoadController;
>   private DataTable _LoadTable;
>
>    public LoadHandler()
>    {
>      _LoadController = _Resolver.Resolve<ILoadController>();
>    }
>
>   public object FillLoadTableAndDoSomethingSpiffy()
>   {
>     _LoadTable = _LoadController.GetLoads();
>     ...proceed on to doing something spiffy and return a value...
>   }
>
> }
>
> So I want to write a unit test to make sure that
> FillLoadTableAndDoSomethingSpiffy returns the expected value, however
> I don't want the LoadController to actually read from the DB, that is
> the part I want to mock so that I can control what that returns.
>
> Is this even possible, and if so could you point me in the right
> direction?
>
> Thanks,
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to