Skip to content
This repository has been archived by the owner on Oct 21, 2018. It is now read-only.

Casting behavior for stubs changed/broken in 3.6 #4

Closed
mscully opened this issue Nov 4, 2009 · 1 comment
Closed

Casting behavior for stubs changed/broken in 3.6 #4

mscully opened this issue Nov 4, 2009 · 1 comment

Comments

@mscully
Copy link

mscully commented Nov 4, 2009

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);
        }

    }
@ayende
Copy link
Owner

ayende commented Nov 8, 2009

Please use the mailing list for those issues

romanfq added a commit to romanfq/rhino-mocks that referenced this issue Jun 15, 2012
EventRaiser.AssertMatchingParameters ignores null as a valid value for
nullable types hence throws with a message similar to this "Parameter ayende#4
is null but should be System.Nullable`1[System.Double]"
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants