In the first example, you're stubbing the implementation of AddNewJobQueueRow. Meaning that when that method on the interface is called, you want your stub to run (which basically does nothing in this example). When you run mainProcessing.CreateJobQueueForCustomer, I imagine that somewhere in there, IJobQueue.AddNewJobQueueRow is called. What will happen is that your stub will be called. I guess it's like saying the "regular" call to IJobQueue.AddNewJobQueueRow is intercepted by RhinoMocks since you've provided your own stubbed implementation.
In the second example, you're not stubbing anything. You're setting an expectation that IJobQueue.AddNewJobQueueRow will be called with particular parameters. Once mainProcessing.CreateJobQueueForCustomer is executed, the call to IJobQueue.AddNewJobQueueRow is made (and tracked by RhinoMocks). You then verify expectations and RhinoMocks looks to see if it tracked any calls to that method (which it did). Does this help? --- Patrick Steele http://weblogs.asp.net/psteele On Wed, Apr 28, 2010 at 3:35 PM, NateGQG <[email protected]> wrote: > Can someone explain to me why the .Stub version of the following code > does not work, but the .Expect version does? If you need more > clarification as to various parts of the code, I can explain further, > but hopefully this should be enough: > > > Doesn't work: > var jobParameterList = new SortedList{{"PKEY", "50"}}; > var stubbedJobQueue = MockRepository.GenerateStub<IJobQueue>(); > > stubbedJobQueue.Stub(x => x.AddNewJobQueueRow(4, jobParameterList)); > var mainProcessing = new MainProcessing(); > mainProcessing.CreateJobQueueForCustomer(stubbedJobQueue); > > stubbedJobQueue.AssertWasCalled(x => > x.AddNewJobQueueRow(Arg<int>.Matches(i => i.Equals(4)), > Arg<SortedList>.Matches(list => list.ContainsKey("PKEY") && > list.ContainsValue("50")))); > > > > > Does work: > var jobParameterList = new SortedList{{"PKEY", "50"}}; > var stubbedJobQueue = MockRepository.GenerateStub<IJobQueue>(); > stubbedJobQueue.Expect(x => x.AddNewJobQueueRow(Arg<int>.Matches(i => > i.Equals(4)), > Arg<SortedList>.Matches(list => list.ContainsKey("PKEY") && > list.ContainsValue("50")))); > > var mainProcessing = new MainProcessing(); > mainProcessing.CreateJobQueueForCustomer(stubbedJobQueue); > > stubbedJobQueue.VerifyAllExpectations(); > > -- > 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.
