Hi everybody!

I'm using RhinoMocks for quite some time. Recently I discovered a good
use for the "GetArgumentsForAllCallsMadeOn()"-method. But I found out
relatively soon that calling BackToRecord() would NOT reset this list.
A short explanartion:
Using the mock, then calling the GetArguments...-method gives me
arguments as expected.
But calling BackToRecord() followed by Replay() on the Mock would
still give me the arguments of calls made prior to the BackToRecord()-
call.
I checked out the code from github, wrote a test for this scenario and
prepared a patch to address this behavior:


 Rhino.Mocks.Tests/RecordingMocks.cs |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/Rhino.Mocks.Tests/RecordingMocks.cs b/Rhino.Mocks.Tests/
RecordingMocks.cs
index 9f58243..14650d0 100644
--- a/Rhino.Mocks.Tests/RecordingMocks.cs
+++ b/Rhino.Mocks.Tests/RecordingMocks.cs
@@ -179,6 +179,27 @@ namespace Rhino.Mocks.Tests
                        Assert.Equal("bar", arguments[1][0]);
                }

+        [Fact]
+        public void
WhenCallingBackToRecord_WillResetArgumentRecordingOfEarlierCalls() {
+            var foo54 = MockRepository.GenerateStub<IFoo54>();
+
+            foo54.Stub(x => x.Bar("foo")).Return(1);
+
+            Assert.Equal(1, foo54.Bar("foo"));
+            Assert.Equal(0, foo54.Bar("bar"));
+
+            IList<object[]> argumentsBeforeBackToRecord =
foo54.GetArgumentsForCallsMadeOn(x =>
x.Bar(Arg<string>.Matches((string s) => true)));
+            Assert.Equal(2, argumentsBeforeBackToRecord.Count);
+            Assert.Equal("foo", argumentsBeforeBackToRecord[0][0]);
+            Assert.Equal("bar", argumentsBeforeBackToRecord[1][0]);
+
+            foo54.BackToRecord();
+            foo54.Replay();
+
+            IList<object[]> argumentsAfterBackToRecord =
foo54.GetArgumentsForCallsMadeOn(x =>
x.Bar(Arg<string>.Matches((string s) => true)));
+            Assert.Equal(0, argumentsAfterBackToRecord.Count);
+        }
+
                [Fact]
                public void CanUseNonRecordReplayModel_Expect()
                {


 Rhino.Mocks/Impl/ProxyInstance.cs |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/Rhino.Mocks/Impl/ProxyInstance.cs b/Rhino.Mocks/Impl/
ProxyInstance.cs
index 63007b3..15ff454 100644
--- a/Rhino.Mocks/Impl/ProxyInstance.cs
+++ b/Rhino.Mocks/Impl/ProxyInstance.cs
@@ -323,6 +323,9 @@ namespace Rhino.Mocks.Impl
                        if (propertiesToSimulate != null &&
                            (options & BackToRecordOptions.PropertyBehavior) != 
0)
                                propertiesToSimulate.Clear();
+            if (methodToActualCalls != null &&
methodToActualCalls.Count > 0) {
+                methodToActualCalls.Clear();
+            }
                }

                private static string GenerateKey(MethodInfo method, object[] 
args)


What do you guys think? Am I missing the concept or intention behind
the GetArguments...-method? Or is my patch worth considering.

Best regards


Dennis Wagner

-- 
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