> i have s.th. like that in a method:
>
> using (IProgramRunner runner = new ProgramRunner (new
> PersistenceManager ()))
> {
> RunPrimaryInstance (args, runner);
> }
> }
>
> in my test file i want to test s.th. in RunPrimaryInstance, so i made
> a PartialMock
>
> IProgramRunner programRunnerMock =
> repository.PartialMock<ProgramRunner> (persistenceManagerStub);
> programRunnerMock.Expect (mock => mock.StartDownload
> (Arg<FileData>.Is.Anything));
>
> Program programMock = repository.PartialMock<Program> ();
> programMock.Expect (mock => mock.RunPrimaryInstance (_args,
> programRunnerMock));
>
> but if i call this test, the second argument of RunPrimaryInstance ist
> not my mock object but a new instance of RunPrimaryInstance, how can i
> force my implementation to use the runner-mock?
Your Program class doesn't use your programRunnerMock because it
doesn't know that object. The method you are testing contains the
following code:
> IProgramRunner runner = new ProgramRunner (new PersistenceManager ())
This will of course always instantiate a new ProgramRunner, never use your mock.
You have two options:
1 - Instead of creating the ProgramRunner in the method you are
testing, create it on the outside and pass it in as a parameter. Then,
in your test code, you can pass in the programRunnerMock.
2 - Or extract the "new ProgramRunner (new PersistenceManager ())"
stuff into a new virtual method. In your partial mock, you can then
expect a call to this method and return your programRunnerMock.
Fabian
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---