Stubbing behavior

0 views
Skip to first unread message

Tim Barcz

unread,
Oct 30, 2009, 3:02:54 PM10/30/09
to Rhino Mocks, rhino-t...@googlegroups.com
Am curious what you all see as the correct behavior.  Am thinking about making an enhancement where the last value set on a stub is what is used. The usage scenario is that I have some common set up code and in some tests want to override with a new stubbed value, however when using expressions the new updated value "doesn't take" (it uses the original).  When using setable properties (ie. PropertyBehavior) the last set value is the one that is returned (which allows me to override as I wish).

Here's an example...which is proper (I'm proposing that the ShowSetable example should be allowed (ie. "last in wins")).  What am I overlooking?

public interface IFoo
{
    bool ReadProperty { get; }
    bool SetableProperty { get; set; }
}

[Test]
public void ShowReadable()
{
        var order = MockRepository.GenerateStub<IFoo>();

        order.Stub(x => x.ReadProperty).Return(false);
        order.Stub(x => x.ReadProperty).Return(true);

        Console.WriteLine(order.ReadProperty );
        Console.WriteLine(order.ReadProperty);
}

Returns: False, False ("first in wins")

[Test]
public void ShowSetable()
{
    var order = MockRepository.GenerateStub<IFoo>();

    order.SetableProperty = false;
    order.SetableProperty = true;

    Console.WriteLine(order.SetableProperty);
    Console.WriteLine(order.SetableProperty);
}

Returns: True, True ("last in wins")

Tim

--
Tim Barcz
Microsoft C# MVP
Microsoft ASPInsider
http://timbarcz.devlicio.us
http://www.twitter.com/timbarcz

Reply all
Reply to author
Forward
0 new messages