title: Mocking Reference Parameter with RhinoMocks
body: <p>I my code, I have the following call: </p>
  
  <pre><code> string proposed=string.Empty;
   validator.IsValid(arg0, arg1, ref proposed);
  </code></pre>
  
  <p>I stub the validator in my test and want that stub to alter the content of the referenced <code>proposed</code> string variable. I tried setting the value of the argument in the WhenCalled-Handler, but this shows no effect.</p>
  
  <pre><code>validatorStub.Stub(x =&gt; x.IsValid(arg0, arg1, ref proposed))
                                              .IgnoreArguments()
                                              .WhenCalled(invocation =&gt;
                                              {
                                                  invocation.Arguments[2] = "123456"; 
                                              }).Throw(new ValidationException(string.Empty));
  </code></pre>
  
  <p>Is this possible with Rhino at all? Unfortunately, I have no way of editing that validator...</p>
  
  <p><strong>EDIT:</strong> Thanks to @FireAlkazar, I understood that I had to better illustrate my test situtation:</p>
  
  <p>Method Code:</p>
  
  <pre><code>public class ClassUnderTest
  {
     public string Arg0{get;set;}
     public string Arg1{get;set;}
     public IValidator Validator {get;set;}
  
     public bool Validate()
     {
        string proposal = string.Empty;
        try
        {
           if (Validator.IsValid(Arg0, Arg1, ref proposal)) return true;
        }
        catch (ValidationException ex)
        {
           if (!string.IsNullOrEmpty(proposal))
           {
              // I want to test this section of code
           }
        }
        return false;
     }                   
  }
  </code></pre>
  
  <p>Test Code:</p>
  
  <pre><code>[TestMethod]
  public void Test_Validate_ValidatorProposes_ReturnsTrue()
  {
      string arg0 = "123456789";
      string arg1 = "201208150030551ABC";
      string prop = "123456";
  
      ClassUnderTest testInstance = new ClassUnderTest();
      testInstance.Arg0 = arg0;
      testInstance.Arg1 = arg1;
  
      IValidator validatorStub = MockRepository.GenerateStub&lt;IValidator&gt;();
      validatorStub.Stub(x =&gt; x.IsValid(Arg&lt;string&gt;.Is.Equal(arg0),
                                        Arg&lt;string&gt;.Is.Equal(arg1),
                                        ref Arg&lt;string&gt;.Ref(Is.Anything(), prop).Dummy))
                   .Throw(new ValidationException(string.Empty));
      testInstance.Validator = validatorStub;
  
      bool actual = testInstance.Validate();
  
      Assert.IsFalse(actual);
  }
  </code></pre>
  
  <p>Still, when I step through this, I see that the ValidatorStub throws the exception i expect it to throw, but never sets the ref parameter.</p>
  
  <hr>
  
  <p><strong>EDIT :</strong> <a href="https://github.com/alaendle/rhino-mocks" rel="nofollow">This branch of RhinoMocks</a> uses a newer version of Castle Core, which solves the issue. The author was kind enough to inform me about this via Google Groups.</p>