Hey guys,
sorry for biggy packing on this topic but I have an issue with
stubbing readonly property:
Here is the bit of code inside the fixture
[Test]
public void InitalizeView() {
// Arrange
string testPin = 12345;
Profile profile = MockRepository.GenerateStub<Profile>();
PIN pin = MockRepository.GenerateStub<PIN>();
pin.Pin = testPin;
profile.Stub(s => s.Pin).Return(pin); // <=== problem is here as it
actually calls getter on the profile.Pin instance
}
Neither PIN nor Profile are sealed so i would expect that i can stub
them properly and not revert to actual property getter call. What am
I missing here?
Thanks,
Roman
On Jan 21, 7:32 am, Chris Missal <[email protected]> wrote:
> A while back, I added an example of this
> here:http://hibernatingrhinos.com/open-source/rhino-mocks/mocking-a-read-o...
>
> What are some other commonly asked questions that I should add to this
> list?http://hibernatingrhinos.com/open-source/rhino-mocks/code-examples
>
>
>
>
>
> On Thu, Jan 21, 2010 at 6:25 AM, Kai <[email protected]> wrote:
> > Thanks.
>
> > Just what I was looking for :o)
>
> > On 21 Jan, 09:42, Alex McMahon <[email protected]> wrote:
> > > Off the top of my head I think if you want to stub a read-only property
> > you
> > > need to use the Stub method:
>
> > > alarmPropertyStub.Stub(x=>x.Value).Return(1);
>
> > > 2010/1/21 Kai <[email protected]>
>
> > > > Hello.
>
> > > > I have just started using Rhino mocks and have a little question. Many
> > > > of our interfaces have properties, but the set method is omitted. The
> > > > properties are set in the class that implements the interface. Is
> > > > there a way to use Rhino Mocks to stub interface like that?
>
> > > > I keep gettign this compilation error.
> > > > error CS0200: Property or indexer IManagedAlarmProperty.DataType'
> > > > cannot be assigned to -- it is read only
>
> > > > Here is my interface:
> > > > public interface IManagedAlarmProperty
> > > > {
> > > > /// <summary>
> > > > /// Property value
> > > > /// </summary>
> > > > object Value { get; }
>
> > > > /// <summary>
> > > > /// datatype of property
> > > > /// </summary>
> > > > Type DataType { get; }
> > > > }
>
> > > > Here is my method that stubs this interface.
> > > > static IManagedOskAlarmProperty CreateAlarmProperty(string
> > > > property)
> > > > {
> > > > IManagedOskAlarmProperty alarmPropertyStub =
> > > > MockRepository.GenerateStub<IManagedOskAlarmProperty>();
> > > > alarmPropertyStub.DataType = typeof(double); <---
> > > > compilation error.
> > > > alarmPropertyStub.Value = 1;
> > > > <-- compilation error.
> > > > return alarmPropertyStub;
> > > > }
>
> > > > Thanks,
> > > > Kai
>
> > > > --
> > > > 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...@googlegrou
> > > > ps.com>
> > <rhinomocks%2bunsubscr...@googlegroups.com>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/rhinomocks?hl=en.–Skjul sitert tekst –
>
> > > – Vis sitert tekst –
>
> > --
> > 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...@googlegrou
> > ps.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/rhinomocks?hl=en.
>
> --
> Chris Missalhttp://chrismissal.lostechies.com/
--
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.