title: Mocking private fields with RhinoMocks
body: <p>I have the following class definition whereby the <code>attribute</code> field is hydrated via reflection by NHibernate.  The field is not exposed as an object but instead I want to hide it's implementation and just provide properties that reference the properties of the <code>attribute</code> field.</p>
  
  <pre><code>    public class CustomerAttribute : ICustomerAttribute
  {
      private IAttribute attribute;
  
      public string DisplayName 
      {
        get { return attribute.DisplayName;}
  
      }
  </code></pre>
  
  <p>}</p>
  
  <p>I'm trying to mock this object with RhinoMocks but I'm not sure how to hydrate the <code>attribute</code> field for testing.  I've tried setting the <code>attribute</code> field manually via reflection but I get a proxy error from RhinoMocks (which makes sense).  </p>
  
  <p>So how do I hydrate the <code>attribute</code> field to I can test the properties of the CustomerAttribute object?</p>
  
  <p>Here is my test right now...</p>
  
  <pre><code>        [Test]
      public void PropertiesTest()
      {
          MockRepository mock = new MockRepository();
          ICustomerAttribute attribute = mock.StrictMock&lt;ICustomerAttribute&gt;();
  
          //Set the attribute field
          FieldInfo fieldInfo = typeof(CustomerAttribute).GetField("attribute",
                                                        BindingFlags.Instance | BindingFlags.SetField |
                                                        BindingFlags.NonPublic);
  
          fieldInfo.SetValue(attribute, new Domain.Attribute()); //This does not work
  
          Expect.Call(attribute.DisplayName).Return("Postal Code");
          mock.ReplayAll();
  
          Assert.AreEqual(true, attribute.DisplayName);
          mock.VerifyAll();
  
      }
  </code></pre>