Awesome, that did get past the exception that I was experiencing. I guess I was assuming that Rhino would automatically set up 'equal' constraints if I didn't specify them explicitly -- now I know.
Unfortunetly I'm running into a different exception that is puzzling me. Once I added the constraints my test code made it all the way down into the playback of the actual code. Once in there I get this exception: System.InvalidOperationException: Previous method 'IRateCalculationService.CalculateSpread(5.62, 1.19);' requires a return value or an exception to throw. at Rhino.Mocks.Impl.RecordMockState.AssertPreviousMethodIsClose() at Rhino.Mocks.Impl.RecordMockState.MethodCall(IInvocation invocation, MethodInfo method, Object[] args) at Rhino.Mocks.MockRepository.MethodCall(IInvocation invocation, Object proxy, MethodInfo method, Object[] args) at Rhino.Mocks.Impl.RhinoInterceptor.Intercept(IInvocation invocation) at Castle.DynamicProxy.AbstractInvocation.Proceed() This is on the first call to method B in my example. It seems fairly straight forward, except I am explicitly returning a value from within my expectation: Expect.Call(rateCalc.CalculateSpread(0, 0)).Constraints(Is.Equal (newBillRate), Is.Equal(newMcdRate)).Return(newSpread) Any ideas? Thanks, Dan Lash On Feb 24, 3:30 am, andreister <andreis...@gmail.com> wrote: > Try constraints. > Bot sure how it should look in VB, but here's the example for C# > > [Test] > public void Test() > { > var foo = MockRepository.GenerateMock<IFoo>(); > int first = 3; > int second = 4; > foo.Expect(x => x.Sum(0, 0)).Constraints(Is.Equal(1), Is.Equal > (2)).Return(first); > foo.Expect(x => x.Sum(0, 0)).Constraints(Is.Equal(1), Is.Equal > (3)).Return(second); > > int result = Boo.Run(foo); > Assert.AreEqual(first + second, result, "Boo.Run() should return > the sum of internal foo.Sum() calls."); > > } > > public class Boo > { > public static int Run(IFoo foo) > { > return foo.Sum(1, 2) + foo.Sum(1, 3); > } > > } > > public interface IFoo > { > int Sum(int a, int b); > > } > > HTS, > Andrew > > On Feb 23, 10:59 pm, Dan Lash <danl...@gmail.com> wrote: > > > > > I have a method I want to test (A). The method makes 2 calls to one of > > its dependencies methods (B) with different parameters. Then it uses > > the return value to do it's work. I want to set up expectations for > > the two calls, and provide my own return values for the two calls so > > that I can verify that A works correctly. > > > Here is basically how the code looks: > > function B(int C, int D) > > return C + D > > end > > > function A(int C, int D, int E) > > F = depend.B(C, D) > > G = depend.B(C, E) > > return F + G > > end > > > And my test looks like this: > > function TestA > > mockB = Mock(ClassWithB) > > realA = ClassWithA(mockB) > > > using Record > > Expect(mockB.B(C, D)).Return(F) > > Expect(mockB.B(C, E)).Return(G) > > end > > > using Playback > > actualF = realA.A(C, D, E) > > end > > > AssertEqual(expectedF, actualF) > > end > > > When I expect the two calls with the different params and different > > returns I get this exception when I run the test: > > > System.InvalidOperationException: Can set only a single return value > > or exception to throw or delegate to execute on the same method call. > > at > > Rhino.Mocks.Expectations.AbstractExpectation.ActionOnMethodNotSpesified > > () > > at Rhino.Mocks.Expectations.AbstractExpectation.set_ReturnValue > > (Object value) > > at Rhino.Mocks.Impl.MethodOptions`1.Return(T objToReturn) > > > How can I set up expectations for multiple parameters and multiple > > return values?- Hide quoted text - > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group. To post to this group, send email to RhinoMocks@googlegroups.com To unsubscribe from this group, send email to rhinomocks+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/RhinoMocks?hl=en -~----------~----~----~----~------~----~------~--~---