Casting behavior for stubs changed/broken in 3.6
Closed this issue · 1 comments
When upgrading our solution from Rhino Mocks 3.5 to 3.6, several tests were broken due to a change in how Rhino Mocks creates stubs in 3.6. In 3.6, a stub will now be created using a remoting proxy if the type being stubbed is a MarshalByRefObject type. A side effect of doing this is that these remote proxy stubs lose their values when cast to (or referenced by) one of its subtypes. I encountered this because we are currently stubbing some database type objects in our tests which are MarshalByRefObject types. The following NUnit tests demonstrate the change in behavior. The tests indicate which version they apply to and assert how the behavior has changed.
Thanks for taking a look.
--matt
[TestFixture]
public class When_using_MarshalByRefObject
{
private const string Name = "@ParamterName1";
private static readonly object Value = 1;
private DbParameter dbParameter = null;
private IDbDataParameter idbParameter = null;
[SetUp]
public void SetUp()
{
dbParameter = MockRepository.GenerateStub<DbParameter>();
dbParameter.ParameterName = Name;
dbParameter.Value = Value;
idbParameter = dbParameter;
}
[Test]
public void Stub_values_missing_after_cast_in_version_36()
{
// Rhino Mocks 3.5 and 3.6 pass
Assert.AreEqual(Name, dbParameter.ParameterName);
Assert.AreEqual(Value, dbParameter.Value);
// Rhino Mocks 3.6 behavior
Assert.IsNull(idbParameter.ParameterName);
Assert.IsNull(idbParameter.Value);
}
[Test]
public void Stub_values_in_tact_after_cast_in_version_35()
{
// Rhino Mocks 3.5 and 3.6 pass
Assert.AreEqual(Name, dbParameter.ParameterName);
Assert.AreEqual(Value, dbParameter.Value);
// Rhino Mocks 3.5 behavior
Assert.AreEqual(Name, idbParameter.ParameterName);
Assert.AreEqual(Value, idbParameter.Value);
}
}
Please use the mailing list for those issues