I'm still convinced that your test code should stub BOTH interfaces,
you have only told Rhino that you wat the IFeature interface to be
stubbed, andtherefore calls made against the INamedObject interface
are not stubbed. So the behaviour is all expected, your second test is
not actually a workaround.
INamedObject { string DisplayName {get; set;} }
IFeature : INamedObject { }
[TestMethod]
public void TestMethodThatPasses()
{
var feature = MockRepository.GenerateStub<IFeature>();
feature.DisplayName = "some name";
Assert.AreEqual("some name", feature.DisplayName);
Assert.AreEqual("some name",
((INamedObject)feature).DisplayName);
}
If however, we create a DisplayName property on the IFeature
interface, this is a different property to that on the INamedObject
interface
INamedObject { string DisplayName {get; set;} }
IFeature : INamedObject { new string DisplayName {get; set;} }
so this test will always fail.
[TestMethod]
public void TestMethodThatFails()
{
var feature = MockRepository.GenerateStub<IFeature>();
feature.DisplayName = "some name";
Assert.AreEqual("some name", feature.DisplayName);
Assert.AreEqual("some name",
((INamedObject)feature).DisplayName);
}
On Feb 11, 10:34 am, Samuel Moura <[email protected]> wrote:
> True, my fault! The INamedObject interface should have the setter as well!
>
> public interface INamedObject
> {
> public string DisplayName {get; set;}
>
> }
>
> (although the why is not relevant here, we are using it so that a legacy
> collection on our software can fire a collection changed when a property
> changes... lets say the collection only fires collection changed for the
> properties defined in the IFeature interface).
>
> -Samuel
>
> On Wed, Feb 10, 2010 at 10:08 PM, bill richards <
>
>
>
> [email protected]> wrote:
> > I'm not 100% certain of this, but I think this behaviour is apparent
> > because you have used a Stub and you have only stubbed the IFeature
> > interface.
>
> > What does puzzle me however is thatyou are not getting an exception
> > from this line:
>
> > ((INamedObject)feature).DisplayName = "some name";
>
> > since this member only has a getter and not a setter, I would expect
> > that you would need to set the return value as follows
>
> > ((INamedObject)feature).Stub(no => no.DisplayName).Return("some
> > name");
>
> > ... without having tried the above code, I'm not even sure if that
> > would/should work.
>
> > On Feb 10, 2:48 pm, Samuel <[email protected]> wrote:
> > > I recently upgraded to RhinoMocks 3.6 and Castle.Windsor 2.1. I
> > > started having an issue with a shadowed property, something like this:
>
> > > public interface INamedObject
> > > {
> > > public string DisplayName {get;}
>
> > > }
>
> > > public interface IFeature : INamedObject
> > > {
> > > new public string DisplayName {get;set;}
>
> > > }
>
> > > [TestMethod]
> > > public void TestMethodThatFails()
> > > {
> > > var feature = MockRepository.GenerateStub<IFeature>();
> > > feature.DisplayName = "some name";
>
> > > Assert.AreEqual("some name", feature.DisplayName);
> > > Assert.AreEqual("some name",
> > > ((INamedObject)feature).DisplayName);
> > > }
>
> > > [TestMethod]
> > > public void TestMethodThatPasses()
> > > {
> > > var feature = MockRepository.GenerateStub<IFeature>();
> > > feature.DisplayName = "some name";
> > > ((INamedObject)feature).DisplayName = "some name";
>
> > > Assert.AreEqual("some name", feature.DisplayName);
> > > Assert.AreEqual("some name",
> > > ((INamedObject)feature).DisplayName);
> > > }
>
> > > Although there is this workaround, is this a breaking change or a bug?
>
> > > I have detailed it on my blog:
> >http://smoura.com/index.php/tdd/2010/02/06/rhinomocks-stub-not-retain...
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Rhino.Mocks" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<rhinomocks%2bunsubscr...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/rhinomocks?hl=en.- Hide quoted text -
>
> - Show quoted text -
--
You received this message because you are subscribed to the Google Groups
"Rhino.Mocks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rhinomocks?hl=en.